https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127716
--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Richard Biener <[email protected]>: https://gcc.gnu.org/g:40df8ff06970e783b424299be509115b574d9f13 commit r17-5579-g40df8ff06970e783b424299be509115b574d9f13 Author: Yongqiang Tian <[email protected]> Date: Thu Oct 22 11:22:36 2026 +1100 tree-optimization: Preserve debug correctness in CRC loop replacement [PR127716] CRC verification treats every outside-loop use of an in-loop definition as an observable use. This includes debug binds, so adding debug information can prevent an otherwise valid CRC loop from being recognized and replaced. Ignore debug statements when checking for outside-loop uses. Ignoring them alone is not sufficient, however: after the loop is replaced, an outside-loop debug bind may still refer to an SSA value whose original final-iteration value no longer exists. Such a bind can make the debugger display an incorrect value. Before replacing the loop, reset outside-loop debug binds that use values defined inside it. The vectorizer already performs the same reset before peeling a loop, so factor that walk into reset_debug_uses_outside_loop and use the common helper from both transformations. Keep debug binds inside the loop unchanged because the transformed loop body still executes once and those binds may remain valid. Add a regression test that verifies both CRC recognition and that the unrecoverable outside-loop value is marked unavailable. Bootstrapped and regression tested on x86_64-pc-linux-gnu. The GCC, G++ and libstdc++ testsuites showed no patch-induced regressions. The new test and the existing gcc.dg CRC tests pass. Assisted-by: OpenAI Codex 5.6 Sol, co-reviewed by Claude and Yongqiang Tian. PR tree-optimization/127716 gcc/ChangeLog: * crc-verification.cc (crc_symbolic_execution::is_used_outside_the_loop): Ignore debug statements when checking for outside-loop uses. * gimple-crc-optimization.cc (crc_optimization::optimize_crc_loop): Reset outside-loop debug binds before replacing the loop. * tree-ssa-loop-manip.cc (reset_debug_uses_outside_loop): New function, factored from vect_do_peeling. * tree-ssa-loop-manip.h (reset_debug_uses_outside_loop): Declare. * tree-vect-loop-manip.cc (vect_do_peeling): Use it. gcc/testsuite/ChangeLog: * gcc.dg/pr127716.c: New test. Suggested-by: Richard Biener <[email protected]> Signed-off-by: Yongqiang Tian <[email protected]>
