http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46675
--- Comment #3 from Uros Bizjak <ubizjak at gmail dot com> 2010-11-27 10:21:20 UTC --- Created attachment 22545 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=22545 preprocessed file The problem is in -fprofile-use. Corresponding .gcda file is not needed to trigger the problem, so: ~/gcc-build/prev-gcc/cc1 -O2 verify-impl.i produces correct object file, while ~/gcc-build/prev-gcc/cc1 -O2 -fprofile-use verify-impl.i produces wrong object file (please note that execution counts are estimated). You can conveniently grep for "printf" in the dumps, since I have left a debugging printf in the loop: for (i = 0; i < npairs; ++i) { jint key = get_int (); if (i > 0 && key <= lastkey) verify_fail_pc ("lookupswitch pairs unsorted", vfr->start_PC); lastkey = key; push_jump (get_int ()); printf ("i = %i\n", i); } While the _.optimized dump without -fprofile-use has similar structure to the original source: --cut here-- <bb 164>: key_215 = get_int (); D.21282_216 = i_224 > 0; D.21283_217 = key_1 >= key_215; D.21284_218 = D.21283_217 & D.21282_216; if (D.21284_218 != 0) goto <bb 165>; else goto <bb 166>; <bb 165>: vfr.14_219 = vfr; D.21287_220 = vfr.14_219->start_PC; verify_fail_pc ("lookupswitch pairs unsorted", D.21287_220); <bb 166>: <bb 167>: # key_1 = PHI <key_215(166), key_1193(291)> # i_1121 = PHI <i_224(166), 0(291)> D.21288_222 = get_int (); push_jump (D.21288_222); printf (&"i = %i\n"[0], i_1121); i_224 = i_1121 + 1; if (i_224 != npairs_212) goto <bb 164>; else goto <bb 168>; <bb 168>: prephitmp.551_882 = vfr; prephitmp.551_882->PC = -1; goto <bb 21>; <L228>: D.21290 = vfy_pop_type (10); [return slot optimization] check_return_type (D.21290); prephitmp.551_883 = vfr; prephitmp.551_883->PC = -1; goto <bb 21>; --cut here-- And using -fprofile-use, it looks somehow strange: --cut here-- <bb 309>: # prephitmp.1170_3787 = PHI <prephitmp.1170_3781(307), prephitmp.1170_3786(308)> D.25872_2132 = prephitmp.1170_3787->current_state; merge_into (npc_2135, D.25872_2132); printf (&"i = %i\n"[0], 0); if (npairs_1969 > 1) goto <bb 290>; else goto <bb 310>; <bb 310>: prephitmp.1288_882 = vfr; prephitmp.1288_882->PC = -1; goto <bb 12>; --cut here-- And sure enough, npairs_1969 is nowhere incremented.