http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48837
--- Comment #6 from Steven Bosscher <steven at gcc dot gnu.org> 2011-05-01 19:56:37 UTC --- In the tail recursion optimization: Breakpoint 3, gimple_call_set_tail (s=0x7ffff7ed3680, tail_p=1 '\001') at ../../trunk/gcc/gimple.h:2241 2241 GIMPLE_CHECK (s, GIMPLE_CALL); (gdb) bt 2 #0 gimple_call_set_tail (s=0x7ffff7ed3680, tail_p=1 '\001') at ../../trunk/gcc/gimple.h:2241 #1 0x0000000000f6d5a3 in optimize_tail_call (t=0x1cd7820, opt_tailcalls=1 '\001') at ../../trunk/gcc/tree-tailcall.c:917 (More stack frames follow...) (gdb) up #1 0x0000000000f6d5a3 in optimize_tail_call (t=0x1cd7820, opt_tailcalls=1 '\001') at ../../trunk/gcc/tree-tailcall.c:917 917 gimple_call_set_tail (stmt, true); (gdb) l 912 913 if (opt_tailcalls) 914 { 915 gimple stmt = gsi_stmt (t->call_gsi); 916 917 gimple_call_set_tail (stmt, true); 918 if (dump_file && (dump_flags & TDF_DETAILS)) 919 { 920 fprintf (dump_file, "Found tail call "); 921 print_gimple_stmt (dump_file, stmt, 0, dump_flags); (gdb) disp debug_bb_n(5) 3: debug_bb_n (5) = ;; basic block 5, loop depth 0, count 0 ;; prev block 4, next block 1 ;; pred: 3 [100.0%] (fallthru,exec) ;; succ: EXIT [100.0%] <bb 5>: Invalid sum of incoming frequencies 3900, should be 6950 # D.2081_1 = PHI <D.2081_5(3)> return D.2081_1; (struct basic_block_def *) 0x7ffff7227548 (gdb) p debug_bb_n(3) ;; basic block 3, loop depth 0, count 0 ;; prev block 2, next block 4 ;; pred: 2 [39.0%] (true,exec) ;; succ: 5 [100.0%] (fallthru,exec) <bb 3>: D.2081_5 = baz (); [tail call] goto <bb 5>; $9 = (struct basic_block_def *) 0x7ffff7227478 (gdb) So far so good. But now compensation code must be inserted for the recursive-call-turned-loop: (gdb) 3: debug_bb_n (5) = ;; basic block 5, loop depth 0, count 0 ;; prev block 4, next block 1 ;; pred: 3 [100.0%] (fallthru,exec) ;; succ: EXIT [100.0%] <bb 5>: Invalid sum of incoming frequencies 3900, should be 6950 # D.2081_1 = PHI <D.2081_5(3)> return D.2081_1; (struct basic_block_def *) 0x7ffff7227548 (gdb) 1040 adjust_return_value (e->src, m_acc, a_acc); 3: debug_bb_n (5) = ;; basic block 5, loop depth 0, count 0 ;; prev block 4, next block 1 ;; pred: 3 [100.0%] (fallthru,exec) ;; succ: EXIT [100.0%] <bb 5>: Invalid sum of incoming frequencies 3900, should be 6950 # D.2081_1 = PHI <D.2081_5(3)> return D.2081_1; (struct basic_block_def *) 0x7ffff7227548 (gdb) 1034 FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR->preds) 3: debug_bb_n (5) = ;; basic block 5, loop depth 0, count 0 ;; prev block 4, next block 1 ;; pred: 3 [100.0%] (fallthru,exec) ;; succ: EXIT [100.0%] <bb 5>: Invalid sum of incoming frequencies 3900, should be 6950 # D.2081_1 = PHI <D.2081_5(3)> acc_tmp.13_10 = add_acc.12_19 + D.2081_1; return acc_tmp.13_10; (struct basic_block_def *) 0x7ffff7227548 (gdb) (I don't see now r127491 can be the cause of this, FWIW.)