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

            Bug ID: 122037
           Summary: unused __builtin_stack_save (due to noreturn) is not
                    removed
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Keywords: missed-optimization, TREE
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: pinskia at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take:
```
void bar1 (char *, int) __attribute__((noreturn));
void foo1 (int size)
{
  char temp[size];
  temp[size-1] = '\0';
  bar1 (temp, size);
}

```

Currently at .optimize we have:
```
  __builtin_stack_save ();
  _1 = (sizetype) size_6(D);
  temp.1_8 = __builtin_alloca_with_align (_1, 8);
  _2 = size_6(D) + -1;
  (*temp.1_8)[_2] = 0;
  bar1 (temp.1_8, size_6(D));

```
That __builtin_stack_save there can be removed.

This can be done in gimple-fold. Basically if the LHS does not exist on the
STACK_SAVE builtin, it can be turned into a NOP.

Reply via email to