[Bug middle-end/126896] New: backward threader cannot duplicate a PHI-of-compares join block

"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=126896

            Bug ID: 126896
           Summary: backward threader cannot duplicate a PHI-of-compares
                    join block
           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
  Target Milestone: ---

Another missing optimization.  I don’t know who’s responsibility this is, cause
I don’t think this maps to ranger.

Fixing this category fixes the following regressions from disabling DOM jump
threading:

    gcc.dg/tree-ssa/phi_on_compare-1.c
    gcc.dg/tree-ssa/phi_on_compare-2.c
    gcc.dg/tree-ssa/phi_on_compare-3.c

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

/* Each arm computes a boolean relational; out-of-ssa leaves
   t = PHI <t_9, t_6>; if (t).  The exit conditional is [0,1] varying
   on every path, so the backward threader rejects every candidate
   path: it only registers a path with a resolved single out-edge.
   DOM's forward threader duplicates the join block into each
   predecessor as a "joiner" and its simplifier replaces the copied
   if (t) with the arm's own comparison, so the bool PHI and the join
   block die.  With DOM threading disabled they survive.  */

void g (void);

void
f (int x, int a, int b, int c, int d)
{
  _Bool t;
  if (x)
    t = a < b;
  else
    t = c < d;
  if (t)
    g ();
}

/* { dg-final { scan-tree-dump-not "PHI" "optimized" } } */
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.