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

            Bug ID: 105135
           Summary: [11/12 Regression] Optimization regression for
                    handrolled branchless assignment
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: andre.schackier at gmail dot com
  Target Milestone: ---

Given the following source code [godbolt](https://godbolt.org/z/rrP3bqGW7):

```cpp
char to_lower_1(const char c) { return c + ((c >= 'A' && c <= 'Z') * 32); }

char to_lower_2(const char c) { return c + (((c >= 'A') & (c <= 'Z')) * 32); }

char to_lower_3(const char c) {
    if (c >= 'A' && c <= 'Z') {
        return c + 32;
    }
    return c;
}
```

compiling with `-O3`

produces the following assembly

```asm
to_lower_1(char):
        lea     eax, [rdi-65]
        cmp     al, 25
        setbe   al
        sal     eax, 5
        add     eax, edi
        ret
to_lower_2(char):
        lea     eax, [rdi-65]
        cmp     al, 25
        setbe   al
        sal     eax, 5
        add     eax, edi
        ret
to_lower_3(char):
        lea     edx, [rdi-65]
        lea     eax, [rdi+32]
        cmp     dl, 26
        cmovnb  eax, edi
        ret
```

Note that gcc-10.3 did produce the same assembly for all 3 functions while
gcc-11 and trunk do not.

Reply via email to