Issue 183132
Summary byte copy loop folds at -Os -O2 -Og but not -Oz
Labels new issue
Assignees
Reporter ZERICO2005
    https://godbolt.org/z/MK7bbrehq

```c
// https://github.com/charlesnicholson/nanoprintf/blob/47af8e576556d7be9621f431e442123eccc056d3/nanoprintf.h#L566
uint64_t npf_double_to_int_rep(double f) {
  // Union-cast is UB pre-C11 and in all C++; the compiler optimizes the code below.
  uint64_t bin;
  char const *src = "" const *)&f;
  char *dst = (char *)&bin;
  for (uint_fast8_t i = 0; i < sizeof(f); ++i) { dst[i] = src[i]; }
  return bin;
}
```
A loop is emitted for this code at `-Oz`. `-O1 -O2 -O3 -Os` emit a bitcast, and `-Og` produces different code, but critically it does not have any loops like `-Oz` does.

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to