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

            Bug ID: 117103
           Summary: GCC trunk emits push + pop at -Oz when a mov could
                    suffice
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dccitaliano at gmail dot com
  Target Milestone: ---

Not a big deal, and maybe there are cases where it's not profitable, but I
found this while testing: https://clang.godbolt.org/z/6K18T1a7a

```
int f(int a, int b, int increment) {
  int i = 0;
  while (i < a) {
    if (i % 2 == 0) {
      i += 2;
    } else {
      i++;
    }
  }
  int j = 0;
  while (j < b) {
    j += increment;
    if (j > b / 2) {
      j += 1;
    }
  }
  return 0;
}
```

-Os emits:

        mov     ecx, 2

-Oz emits:

        push    2
[...]
        pop     rcx


Another interesting (maybe?, not sure) bit is that the loop could be elided
entirely. I can file another bug if there's interest, or just reuse this one.

Reply via email to