https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108552
--- Comment #26 from Richard Biener <rguenth at gcc dot gnu.org> --- And yes, to IV optimization the gcov counter for the loop body is just another IV candidate that can be used, and in this case it allows to elide the otherwise unused original IV. Now, in principle we should have applied store-motion and not only PRE which would have avoided the issue, not tricking the RA into reloading the value from where we store it in the loop, but the kernel uses -fno-tree-loop-im, preventing that. If you enable that you'd get <bb 7> [local count: 105119324]: __gcov0.prep_compound_page_I_lsm.1755_4 = __gcov0.prep_compound_page[7]; _92 = (long unsigned int) page_12(D); _57 = _92 + 1; _119 = page_12(D) + 40; ivtmp.1762_136 = (unsigned int) _119; <bb 8> [local count: 955630225]: # i_66 = PHI <i_17(8), 1(7)> # ivtmp.1762_6 = PHI <ivtmp.1762_46(8), ivtmp.1762_136(7)> p_15 = (struct page *) ivtmp.1762_6; MEM <struct address_space *> [(union *)p_15 + 12B] = 1024B; MEM[(volatile long unsigned int *)p_15 + 4B] ={v} _57; i_17 = i_66 + 1; ivtmp.1762_46 = ivtmp.1762_6 + 40; if (nr_pages_11 != i_17) goto <bb 8>; [89.00%] else goto <bb 9>; [11.00%] <bb 9> [local count: 105119324]: _73 = (unsigned int) nr_pages_11; _163 = _73 + 4294967294; _159 = (long long int) _163; _1 = __gcov0.prep_compound_page_I_lsm.1755_4 + 1; PROF_edge_counter_74 = _1 + _159; __gcov0.prep_compound_page[7] = PROF_edge_counter_74; which is the desired optimization, handling the counter in the loop like an induction variable instead of going through memory.