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

            Bug ID: 116699
           Summary: factor_out_conditional_operation does not ignore
                    PREDICT/NOP sometimes
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: pinskia at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take:
```
short f(int a, int b, int c)
{
  if (b)  return (c > a ? c : a);
  return 0;
}
```

The factoring out the convert/cast happens only at phiopt2 because in phiopt1
we have:
```
  _1 = MAX_EXPR <a_5(D), c_6(D)>;
  _7 = (short intD.17) _1;
  // predicted unlikely by early return (on trees) predictor.
;;    succ:       4 (FALLTHRU,EXECUTABLE) /app/example.cpp:3:29

```

The code right now does:
          gsi = gsi_for_stmt (arg0_def_stmt);
          gsi_next_nondebug (&gsi);
          if (!gsi_end_p (gsi))
            return NULL;

Without considering GIMPLE_NOP/GIMPLE_PREDICT between the statement and the
end.

There needs to be a small loop added after the gsi_next_nondebug but before the
gsi_end_p:
  /* Skip nops and predicates. */
  while (!gsi_end_p (gsi)
         && (gimple_code (gsi_stmt (gsi)) == GIMPLE_NOP
             || gimple_code (gsi_stmt (gsi)) == GIMPLE_PREDICT))
    gsi_next_nondebug (&gsi);

Reply via email to