https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127716

--- Comment #1 from Yongqiang Tian <yqtian668 at gmail dot com> ---
I prepared a minimal patch that ignores `GIMPLE_DEBUG` uses in
`crc_symbolic_execution::is_used_outside_the_loop`:

```c
if (is_gimple_debug (use_stmt))
  continue;
```

This makes the CRC transformation independent of `-g`. The targeted test fails
before the change with both an `-fcompare-debug` mismatch and a missing CRC
transformation, and passes after the change. A full bootstrap and regression
test on x86_64-pc-linux-gnu also completed without patch-induced regressions.

However, while checking the resulting debug information, I noticed a limitation
in the CRC transformation itself. The reproducer contains a debug-only local:

```c
u16 last __attribute__ ((unused)) = sh;
```

Here, `last` should describe the value of `sh` after the sixteenth loop
iteration. After the CRC loop is replaced, the final optimized dump instead
contains:

```text
# DEBUG D#1 => data_5(D) << 1
# DEBUG last => D#1
```

The emitted DWARF likewise describes `last` as the original input shifted left
by one. This appears to be the first-iteration value rather than the value from
the final iteration. The generated ordinary code is still correct, and the SSA
references are valid, but a debugger may display an incorrect value for `last`.

My understanding is that the minimal `is_gimple_debug` change is still
necessary because debug statements should not affect whether the CRC
transformation is performed. I am less certain about the appropriate treatment
of the debug uses whose dynamic values disappear when the loop condition is
changed.

Would it be appropriate to submit the minimal fix for PR127716 first and handle
the inaccurate debug location separately? Alternatively, should this patch also
call `reset_debug_uses` for definitions inside the transformed loop before
`gimple_cond_make_false`, so that values such as `last` become unavailable
rather than being described incorrectly?

Any guidance on the preferred scope and the correct place to reset these debug
uses would be greatly appreciated.

Reply via email to