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

            Bug ID: 125133
           Summary: Optimization: v = *(*p)++; can make different code
                    from v = **p, p++;
           Product: gcc
           Version: 15.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: other
          Assignee: unassigned at gcc dot gnu.org
          Reporter: Explorer09 at gmail dot com
  Target Milestone: ---

Compile Explorer link:
https://godbolt.org/z/G3sj3jbY4

```c
// <https://gitlab.com/Explorer09/utf_convert/-/blob/main/utf9.c>
#include <stdint.h>
uint_least32_t utf9_to_code_point_simp(const uint_least16_t **sequence)
{
    unsigned int nonet;
    uint_least32_t value = 0;
    do {
        nonet = *(*sequence)++;
        value = (value << 8) | (nonet & 0xFF);
    } while (nonet >= 0x100);
    return value;
}
uint_least32_t utf9_to_code_point_simp_2(const uint_least16_t **sequence)
{
    unsigned int nonet;
    uint_least32_t value = 0;
    do {
        nonet = **sequence;
        (*sequence)++;
        value = (value << 8) | (nonet & 0xFF);
    } while (nonet >= 0x100);
    return value;
}
```

The expected result is both functions compile to same code, because there is no
semantic difference.

I tested on x86-64, AArch64 and RV64, and the generated code is slightly
different without a good reason.

(Both -O2 and -Os optimization modes are tested.)

Reply via email to