Bug 23948 - [4.1 Regression] internal compiler error: verify_stmts failed
Summary: [4.1 Regression] internal compiler error: verify_stmts failed
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.1.0
: P1 normal
Target Milestone: 4.1.0
Assignee: Paolo Bonzini
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: ice-on-valid-code, patch
: 25909 (view as bug list)
Depends on:
Blocks: 23109 24123
  Show dependency treegraph
 
Reported: 2005-09-18 13:12 UTC by Harold Naparst
Modified: 2006-01-23 01:26 UTC (History)
7 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-09-21 08:12:59


Attachments
preprocessed output with -save-temps (138.44 KB, application/octet-stream)
2005-09-18 13:16 UTC, Harold Naparst
Details
patch under testing (3.34 KB, patch)
2005-09-22 08:12 UTC, Paolo Bonzini
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Harold Naparst 2005-09-18 13:12:30 UTC
When compiling the attached file, the compilation gives the error shown.
How do I attach the file?  I don't see a button to do so.
Comment 1 Harold Naparst 2005-09-18 13:16:18 UTC
Created attachment 9764 [details]
preprocessed output with -save-temps
Comment 2 Harold Naparst 2005-09-18 15:30:19 UTC
Works in 4.0 cvs.
Comment 3 Andrew Pinski 2005-09-18 16:33:37 UTC
How did you compile the file?
Also what is the date on 4.1.0?

I tried -O[0-3] with "4.1.0 20050916" and I could not reproduce this.
Comment 4 Harold Naparst 2005-09-18 18:02:42 UTC
OK, please bear with me.  I'm not as talented as you at this, but I'm trying.
I think we're both using the 9/16/05 build, since the top entry in the
"ChangeLog" file is 9/16/05.

The compile command that generates the error is:

 g++-4.1 -DHAVE_CONFIG_H -I. -I. -I..  -I ./win -I../lib -I../api -I../db
-I../RSAEuro/source -I../client -I../tools -I../sched  -pthread -include
../config.h -O3 -D__NO_CTYPE -I../lib -I../api -I../db -I../RSAEuro/source
-I../client -I../tools -I../sched  -pthread -include ../config.h -DACML -O3
-ffast-math -funroll-all-loops -fpeel-loops -ftracer -funswitch-loops
-ftree-vectorize -march=k8  -g  -pthread -MT boinc_client-cs_scheduler.o -MD -MP
-MF ".deps/boinc_client-cs_scheduler.Tpo" -c -o boinc_client-cs_scheduler.o
cs_scheduler.C cs_scheduler.C: In member function 'int
CLIENT_STATE::make_scheduler_request(PROJECT*)':
cs_scheduler.C:200: error: statement marked for throw in middle of block
#   bufD.54331_943(ab) = V_MAY_DEF <bufD.54331_939>;
#   SFT.1187D.68458_944(ab) = V_MAY_DEF <SFT.1187D.68458_940>;
#   SFT.1188D.68459_945(ab) = V_MAY_DEF <SFT.1188D.68459_941>;
#   SFT.1189D.68460_946(ab) = V_MAY_DEF <SFT.1189D.68460_942>;
prrsD.54346_136 = potentially_runnable_resource_share (thisD.54329_135);

cs_scheduler.C:200: internal compiler error: verify_stmts failed
Please submit a full bug report,
with preprocessed source if appropriate.


From this command, do you need me to post any other files?  I can't really tell,
to be honest, since I'm not too sure what all those -M flags do.
Comment 5 Andrew Pinski 2005-09-18 18:06:22 UTC
(In reply to comment #4)
> From this command, do you need me to post any other files?  I can't really tell,
> to be honest, since I'm not too sure what all those -M flags do.

No I can reproduce it now.
Comment 6 Andrew Pinski 2005-09-18 18:10:50 UTC
Note only -O3 -ffast-math is required to reproduce this bug.

Reducing.
Comment 7 Andrew Pinski 2005-09-18 18:16:58 UTC
-O2 -finline-functions -ffast-math is enough to reproduce this.
Comment 8 Andrew Pinski 2005-09-18 18:54:12 UTC
Reduced testcase:
struct MIOFILE {
  ~MIOFILE();
};
double potentially_runnable_resource_share();
void f1(double);
int make_scheduler_request(double a)
{
  MIOFILE mf;
  double prrs = potentially_runnable_resource_share();
  f1(a/prrs);
  f1(1/prrs);
}

---

-O1 -ffast-math is enough to reproduce this reduced testcase.
This is caused by the recip pass.
Comment 9 janis187 2005-09-20 21:28:15 UTC
The ICE begins with these patches (the second adds a missing file for the first)
from bonzini:

  http://gcc.gnu.org/ml/gcc-cvs/2005-05/msg00791.html
  http://gcc.gnu.org/ml/gcc-cvs/2005-05/msg00792.html
Comment 10 Richard Biener 2005-09-21 14:18:29 UTC
We insert the reciprocal computation correctly after the call to 
  double prrs = potentially_runnable_resource_share();
but as this call may trap and is the last instruction in the basic block,
inserting there is obviously bogous.

We'd need to insert a new BB or need a way to insert on the EXIT_EDGE.  And
make sure critical edges are split.
Comment 11 paolo.bonzini@lu.unisi.ch 2005-09-21 14:33:13 UTC
Subject: Re:  [4.1 Regression] internal compiler
 error: verify_stmts failed

rguenth at gcc dot gnu dot org wrote:

>------- Additional Comments From rguenth at gcc dot gnu dot org  2005-09-21 14:18 -------
>We insert the reciprocal computation correctly after the call to 
>  double prrs = potentially_runnable_resource_share();
>but as this call may trap and is the last instruction in the basic block,
>inserting there is obviously bogous.
>
>We'd need to insert a new BB or need a way to insert on the EXIT_EDGE.  And
>make sure critical edges are split.
>  
>
No, I think we have to rethink the place where we insert the division.  
It needs to be closer to the divide (just before), not right after the 
definition.  When we have flag_trapping_math, this is quite hard to do 
(there may be even multiple places to insert the divide!).

I also did not understand why you had to fiddle with postdominators :-) 
to fix PR23309.  I have a prototype patch but it will probably be a 
while before I can sit, look if it really works, and test it properly.

Paolo
Comment 12 Richard Biener 2005-09-21 14:44:12 UTC
Fixing like the following, but inserting onto the right edge(s) -
single_succ_edge actually doesn't work here.

diff -c -3 -p -r2.5 tree-ssa-math-opts.c
*** tree-ssa-math-opts.c        9 Aug 2005 03:28:32 -0000       2.5
--- tree-ssa-math-opts.c        21 Sep 2005 14:43:08 -0000
*************** execute_cse_reciprocals_1 (block_stmt_it
*** 111,117 ****
    if (where == PR_BEFORE_BSI)
      bsi_insert_before (bsi, new_stmt, BSI_SAME_STMT);
    else if (where == PR_AFTER_BSI)
!     bsi_insert_after (bsi, new_stmt, BSI_NEW_STMT);
    else if (where == PR_ON_ENTRY_EDGE)
      bsi_insert_on_edge (single_succ_edge (ENTRY_BLOCK_PTR), new_stmt);
    else
--- 111,122 ----
    if (where == PR_BEFORE_BSI)
      bsi_insert_before (bsi, new_stmt, BSI_SAME_STMT);
    else if (where == PR_AFTER_BSI)
!     {
!       if (stmt_ends_bb_p (bsi_stmt (*bsi)))
!       bsi_insert_on_edge (single_succ_edge (bsi->bb), new_stmt);
!       else
!       bsi_insert_after (bsi, new_stmt, BSI_NEW_STMT);
!     }
    else if (where == PR_ON_ENTRY_EDGE)
      bsi_insert_on_edge (single_succ_edge (ENTRY_BLOCK_PTR), new_stmt);
    else
Comment 13 Paolo Bonzini 2005-09-22 07:00:06 UTC
I don't know the tree-cfg bits very well, but the patch seems wrong; you are not
committing the edge insertion.
Comment 14 Paolo Bonzini 2005-09-22 07:09:06 UTC
I have a patch but it only works in the -fno-trapping-math case.  Given that
trapping math is much more complex, that the code quality improves for
-ftrapping-math, and that we are late in the development of 4.1, I'll probably
punt and disable the optimization for -ftrapping-math.
Comment 15 Paolo Bonzini 2005-09-22 08:12:08 UTC
Created attachment 9789 [details]
patch under testing
Comment 16 Paolo Bonzini 2005-09-23 09:58:35 UTC
I've rewritten execute_cse_reciprocals, I think the only useful solution is to
implement the optimal scheme for inserting reciprocals, and fix this bug in the
process.

My algorithm builds a "mock" dominator tree including only the basic blocks with
the divides and their common dominators, and then inserts divides whenever it is
necessary to satisfy these conditions:

1) if -ftrapping-math, the basic block must have one divide

2) in addition, at least two divides must either be in the basic block, or
postdominate it.

I still have to run some coverage tests, then I'll post the patch.  If anybody
wants to help, I'd be thankful.
Comment 17 Paolo Bonzini 2005-09-25 12:48:53 UTC
Posted the patch for the algorithm I had sketched in the previous comments.
Comment 18 Steven Bosscher 2005-10-15 17:26:18 UTC
...to fix a mouse click on the wrong radio button :-)

*** This bug has been marked as a duplicate of 24232 ***
Comment 19 Steven Bosscher 2005-10-15 17:27:15 UTC
aaaaargh
Comment 20 Mark Mitchell 2005-10-31 05:48:25 UTC
This is a showstopper.
Comment 21 Diego Novillo 2006-01-05 14:40:58 UTC
(In reply to comment #20)
> This is a showstopper.
> 
I'm reviewing bonzini's patch today.

Comment 22 Paolo Bonzini 2006-01-11 13:02:24 UTC
Subject: Bug 23948

Author: bonzini
Date: Wed Jan 11 13:02:18 2006
New Revision: 109578

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=109578
Log:
gcc:
2006-01-11  Paolo Bonzini  <bonzini@gnu.org>

	PR tree-optimization/23109
	PR tree-optimization/23948
	PR tree-optimization/24123

	* Makefile.in (tree-ssa-math-opts.o): Adjust dependencies.
        * tree-cfg.c (single_noncomplex_succ): New.
        * tree-flow.h (single_noncomplex_succ): Declare it.
        * tree-ssa-math-opts.c (enum place_reciprocal): Remove.
        * tree-ssa-math-opts.c (enum place_reciprocal): Remove.
        (struct occurrence, occ_head, occ_pool, is_divide_by, compute_merit,
	insert_bb, register_division_in, insert_reciprocals,
	replace_reciprocal, free_bb): New.
        (execute_cse_reciprocals_1): Rewritten.
        (execute_cse_reciprocals): Adjust calls to execute_cse_reciprocals_1.
        Do not commit any edge insertion.  Always compute dominators and
        create the allocation pool.
        * target-def.h (TARGET_MIN_DIVISIONS_FOR_RECIP_MUL): New.
	* target.h (struct gcc_target): Add min_divistions_for_recip_mul.
	* targhooks.c (default_min_divistions_for_recip_mul): New.
	* targhooks.h (default_min_divistions_for_recip_mul): New prototype.
        * passes.c (init_optimization_passes): Run recip after tree loop
        optimizations.
        * doc/tm.texi (Misc): Document TARGET_MIN_DIVISIONS_FOR_RECIP_MUL.

gcc/testsuite:
2006-01-11  Paolo Bonzini  <bonzini@gnu.org>
        
        PR tree-optimization/23109
        PR tree-optimization/23948
        PR tree-optimization/24123

        * gcc.dg/tree-ssa/recip-3.c, gcc.dg/tree-ssa/recip-4.c,
        gcc.dg/tree-ssa/recip-5.c, gcc.dg/tree-ssa/recip-6.c,
        gcc.dg/tree-ssa/recip-7.c, gcc.dg/tree-ssa/pr23109.c,
        g++.dg/tree-ssa/pr23948.C: New testcases.
        * gcc.dg/tree-ssa/recip-2.c, gcc.dg/tree-ssa/pr23234.c: Provide
	three divisions in order to do the optimization.


Added:
    trunk/gcc/testsuite/g++.dg/tree-ssa/pr23948.C
    trunk/gcc/testsuite/gcc.dg/tree-ssa/pr23109.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/recip-3.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/recip-4.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/recip-5.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/recip-6.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/recip-7.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/Makefile.in
    trunk/gcc/doc/tm.texi
    trunk/gcc/passes.c
    trunk/gcc/target-def.h
    trunk/gcc/target.h
    trunk/gcc/targhooks.c
    trunk/gcc/targhooks.h
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.dg/tree-ssa/pr23234.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/recip-2.c
    trunk/gcc/tree-cfg.c
    trunk/gcc/tree-flow.h
    trunk/gcc/tree-ssa-math-opts.c

Comment 23 Paolo Bonzini 2006-01-11 14:29:39 UTC
Subject: Bug 23948

Author: bonzini
Date: Wed Jan 11 14:29:29 2006
New Revision: 109586

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=109586
Log:
gcc:
2006-01-11  Paolo Bonzini  <bonzini@gnu.org>

	PR tree-optimization/23109
	PR tree-optimization/23948
	PR tree-optimization/24123

	* Makefile.in (tree-ssa-math-opts.o): Adjust dependencies.
        * tree-cfg.c (single_noncomplex_succ): New.
        * tree-flow.h (single_noncomplex_succ): Declare it.
        * tree-ssa-math-opts.c (enum place_reciprocal): Remove.
        * tree-ssa-math-opts.c (enum place_reciprocal): Remove.
        (struct occurrence, occ_head, occ_pool, is_divide_by, compute_merit,
	insert_bb, register_division_in, insert_reciprocals,
	replace_reciprocal, free_bb): New.
        (execute_cse_reciprocals_1): Rewritten.
        (execute_cse_reciprocals): Adjust calls to execute_cse_reciprocals_1.
        Do not commit any edge insertion.  Always compute dominators and
        create the allocation pool.
        * target-def.h (TARGET_MIN_DIVISIONS_FOR_RECIP_MUL): New.
	* target.h (struct gcc_target): Add min_divistions_for_recip_mul.
	* targhooks.c (default_min_divistions_for_recip_mul): New.
	* targhooks.h (default_min_divistions_for_recip_mul): New prototype.
        * passes.c (init_optimization_passes): Run recip after tree loop
        optimizations.
        * doc/tm.texi (Misc): Document TARGET_MIN_DIVISIONS_FOR_RECIP_MUL.

gcc/testsuite:
2006-01-11  Paolo Bonzini  <bonzini@gnu.org>
        
        PR tree-optimization/23109
        PR tree-optimization/23948
        PR tree-optimization/24123

        * gcc.dg/tree-ssa/recip-3.c, gcc.dg/tree-ssa/recip-4.c,
        gcc.dg/tree-ssa/recip-5.c, gcc.dg/tree-ssa/recip-6.c,
        gcc.dg/tree-ssa/recip-7.c, gcc.dg/tree-ssa/pr23109.c,
        g++.dg/tree-ssa/pr23948.C: New testcases.
        * gcc.dg/tree-ssa/recip-2.c, gcc.dg/tree-ssa/pr23234.c: Provide
	three divisions in order to do the optimization.


Added:
    branches/gcc-4_1-branch/gcc/testsuite/g++.dg/tree-ssa/pr23948.C
      - copied unchanged from r109578, trunk/gcc/testsuite/g++.dg/tree-ssa/pr23948.C
    branches/gcc-4_1-branch/gcc/testsuite/gcc.dg/tree-ssa/pr23109.c
      - copied unchanged from r109578, trunk/gcc/testsuite/gcc.dg/tree-ssa/pr23109.c
    branches/gcc-4_1-branch/gcc/testsuite/gcc.dg/tree-ssa/recip-3.c
      - copied unchanged from r109578, trunk/gcc/testsuite/gcc.dg/tree-ssa/recip-3.c
    branches/gcc-4_1-branch/gcc/testsuite/gcc.dg/tree-ssa/recip-4.c
      - copied unchanged from r109578, trunk/gcc/testsuite/gcc.dg/tree-ssa/recip-4.c
    branches/gcc-4_1-branch/gcc/testsuite/gcc.dg/tree-ssa/recip-5.c
      - copied unchanged from r109578, trunk/gcc/testsuite/gcc.dg/tree-ssa/recip-5.c
    branches/gcc-4_1-branch/gcc/testsuite/gcc.dg/tree-ssa/recip-6.c
      - copied unchanged from r109578, trunk/gcc/testsuite/gcc.dg/tree-ssa/recip-6.c
    branches/gcc-4_1-branch/gcc/testsuite/gcc.dg/tree-ssa/recip-7.c
      - copied unchanged from r109578, trunk/gcc/testsuite/gcc.dg/tree-ssa/recip-7.c
Modified:
    branches/gcc-4_1-branch/gcc/ChangeLog
    branches/gcc-4_1-branch/gcc/Makefile.in
    branches/gcc-4_1-branch/gcc/doc/tm.texi
    branches/gcc-4_1-branch/gcc/passes.c
    branches/gcc-4_1-branch/gcc/target-def.h
    branches/gcc-4_1-branch/gcc/target.h
    branches/gcc-4_1-branch/gcc/targhooks.c
    branches/gcc-4_1-branch/gcc/targhooks.h
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_1-branch/gcc/testsuite/gcc.dg/tree-ssa/pr23234.c
    branches/gcc-4_1-branch/gcc/testsuite/gcc.dg/tree-ssa/recip-2.c
    branches/gcc-4_1-branch/gcc/tree-cfg.c
    branches/gcc-4_1-branch/gcc/tree-flow.h
    branches/gcc-4_1-branch/gcc/tree-ssa-math-opts.c

Comment 24 Paolo Bonzini 2006-01-11 14:31:12 UTC
patch committed
Comment 25 Andrew Pinski 2006-01-23 01:26:11 UTC
*** Bug 25909 has been marked as a duplicate of this bug. ***