[Bug middle-end/126904] New: backward threader: no path-sensitive load CSE (value numbering?)

"aldyh at gcc dot gnu.org via Gcc-bugs" <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126904

            Bug ID: 126904
           Summary: backward threader: no path-sensitive load CSE (value
                    numbering?)
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: aldyh at gcc dot gnu.org
                CC: amacleod at redhat dot com, law at gcc dot gnu.org,
                    rguenth at gcc dot gnu.org
            Blocks: 126010
  Target Milestone: ---

This is one case where FRE/PRE cannot currently rescue the backward threader
from what is currently being done by DOM’s avail_exprs.

[Full disclosure, as mentioned earlier I used Claude Fable to reduce the
missing optimizations I’m auditing for the backwards threader.  Is it useful to
stick an Assisted-by tag here in the PR?  I’ve reduced and verified myself, but
the paragraph analyzing the cause is NOT mine.  For the record, I’m not using
AI to do a report-and-run here… I’m more than happy to do some of the leg work,
answer questions, and reproduce, but I know this is a sensitive subject.]

/* { dg-do compile } */
/* { dg-options "-O2 --param=dom-jump-threading=0
-fdump-tree-threadfull1-details" } */

/* The two conditionals test two different SSA names that are loads
   of the same location *p.  On the path where the first is true
   there is no intervening store, so the second load equals the first
   and the second conditional is false.  DOM's avail-exprs sees this
   and threads the path; the path ranger has no memory value
   numbering, sees the second load as VARYING, and rejects.  FRE/PRE
   cannot pre-empt the problem: foo () on the other arm clobbers *p
   (no full redundancy), and the possibly non-returning spin ()
   before the may-trap load keeps PRE from making it anticipable.  */

void foo (void);

static void __attribute__((noinline))
spin (int n)
{
  while (n)
    ;
}

void
f (int *p, int k)
{
  if (*p == k)
    ;
  else
    foo ();
  spin (k);
  if (*p != k)
    foo ();
}

/* { dg-final { scan-tree-dump-times "Registering jump thread" 1 "threadfull1"
} } */


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126010
[Bug 126010] [meta-bug] Remove DOM
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.