On Wed, Sep 16, 2026 at 2:19 PM Yongqiang Tian <[email protected]> wrote:
>
> A DEBUG_INSN VAR_LOCATION can mention if_info->x without representing an
> ordinary use.  Exclude debug instructions from the overlap scan so that
> debug-only payloads do not suppress min/max if-conversion.
>
>         PR rtl-optimization/127423
>
> gcc/ChangeLog:
>
>         * ifcvt.cc (noce_get_alt_condition): Ignore debug instructions when
>         checking whether if_info->x is mentioned in the interval.
>
> gcc/testsuite/ChangeLog:
>
>         * gcc.target/riscv/pr127423.c: New test.
>
> Assisted-by: OpenAI Codex 5.6 Sol, co-reviewed by Claude and Yongqiang Tian.
> Signed-off-by: Yongqiang Tian <[email protected]>
> ---
>  gcc/ifcvt.cc                              |  3 ++-
>  gcc/testsuite/gcc.target/riscv/pr127423.c | 17 +++++++++++++++++
>  2 files changed, 19 insertions(+), 1 deletion(-)
>  create mode 100644 gcc/testsuite/gcc.target/riscv/pr127423.c
>
> diff --git a/gcc/ifcvt.cc b/gcc/ifcvt.cc
> index 7d23ce115bd..618c2976c5d 100644
> --- a/gcc/ifcvt.cc
> +++ b/gcc/ifcvt.cc
> @@ -3038,7 +3038,8 @@ noce_get_alt_condition (noce_if_info *if_info, rtx 
> target,
>
>    /* X may not be mentioned in the range (cond_earliest, jump].  */
>    for (insn = if_info->jump; insn != *earliest; insn = PREV_INSN (insn))
> -    if (INSN_P (insn) && reg_overlap_mentioned_p (if_info->x, PATTERN 
> (insn)))
> +    if (NONDEBUG_INSN_P (insn)
> +       && reg_overlap_mentioned_p (if_info->x, PATTERN (insn)))

Do we properly reset a DEBUG_INSN if the reg is mentioned in it?

>        return NULL;
>
>    /* A and B may not be modified in the range [cond_earliest, jump).  */
> diff --git a/gcc/testsuite/gcc.target/riscv/pr127423.c 
> b/gcc/testsuite/gcc.target/riscv/pr127423.c
> new file mode 100644
> index 00000000000..47caa270644
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/pr127423.c
> @@ -0,0 +1,17 @@
> +/* PR rtl-optimization/127423 */
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fno-tree-forwprop -fdisable-tree-phiopt1 
> -fdisable-tree-phiopt2 -fdisable-tree-phiopt3 -fdisable-tree-phiopt4 
> -march=rv64gc_zbb -mabi=lp64d -ffunction-sections -fcompare-debug" } */
> +
> +#define ATTR __attribute__ ((noinline, noclone))
> +
> +ATTR int
> +debug_payload_min (int a, int b)
> +{
> +  _Bool pred = a < b;
> +  asm volatile ("" : : "r" (pred));
> +  int result = b;
> +  int xghost = a;
> +  if (pred)
> +    result = a;
> +  return result;
> +}
> --
> 2.34.1
>

Reply via email to