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

            Bug ID: 121712
           Summary: not removing loop when iterates once only
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take:
```
void f0(int *a, int *b, int *c)
{
  auto t = b - a;
  if (t == 1)
  {
    do {
        a++;
        *c += 1;
        c++;
    } while (a != b);
  }
}

#include <vector>

void f1(std::vector<int> &a, int *c)
{
  if (a.size() != 1)
    return;
  for(auto b : a)
  {
    *c += 1;
    c++;
  }
}
```

f is a reduced version of f1 (so it does not have the issue referenced in PR
121710). 

Basically these two should reduce down to just:
```
void f0_tgt(int *a, int *b, int *c)
{
  auto t = b - a;
  if (t == 1)
    (*c) ++;
}
void f1(std::vector<int> &a, int *c)
{
  if (a.size() != 1)
    return;
  (*c)++;
}
```

Reply via email to