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

            Bug ID: 117671
           Summary: unroll estimate does not take into account later undef
                    stmt removal
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rguenth at gcc dot gnu.org
  Target Milestone: ---

c-c++-common/ubsan/unreachable-3.c does

struct snic {
    unsigned int wq_count;
    struct vnic_wq_ctrl *wq[1];
    int wq_lock[1];
};
void snic_log_q_error(struct snic *snic)
{
    unsigned int i;
    for (i = 0; i < snic->wq_count; i++)
        ioread32(&snic->wq[i]->error_status);
}

and cunroll sees

  <bb 3> [local count: 536870912]:
  # i_13 = PHI <i_9(6), 0(5)>
  __builtin___sanitizer_cov_trace_pc ();
  _1 = snic_7(D)->wq[i_13];
  _2 = &_1->error_status;
  ioread32 (_2);
  i_9 = i_13 + 1;
  _3 = snic_7(D)->wq_count;
  if (_3 > i_9)
    goto <bb 6>; [50.00%]
  else
    goto <bb 4>; [50.00%]

  <bb 6> [local count: 268435456]:
  goto <bb 3>; [100.00%]

when estimating sizes we do not consider that we later mark

  _1 = snic_7(D)->wq[1];

and everything below as unreachable ().  For this reason the above testcase
will be XFAILed with one of my incoming patches to better handle stmts
with side-effects (in the above case the ioread32 call).

Reply via email to