public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug regression/105126] New: Optimization regression gcc inserts not needed movsx when using switch statement
@ 2022-04-01 13:42 andre.schackier at gmail dot com
  2022-04-01 15:39 ` [Bug regression/105126] " marxin at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: andre.schackier at gmail dot com @ 2022-04-01 13:42 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 105126
           Summary: Optimization regression gcc inserts not needed movsx
                    when using switch statement
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: regression
          Assignee: unassigned at gcc dot gnu.org
          Reporter: andre.schackier at gmail dot com
  Target Milestone: ---

Given the following source code:

```cpp
bool is_bin_0(const char c) { return (c == '0' || c == '1'); }

bool is_bin_1(const char c) {
    switch (c) {
        case '0':
        case '1':
            return true;

        default:
            return false;
    }
}

```

compiling with `-O3` gives the following output:

```asm
is_bin_0(char):
        sub     edi, 48
        cmp     dil, 1
        setbe   al
        ret
is_bin_1(char):
        movsx   edi, dil
        sub     edi, 48
        cmp     edi, 1
        setbe   al
        ret
```

The version using a switch generates an extra movsx instruction which, as far
is I understand the x86 CPU registers is not needed since DIL is the lower 8
bits of EDI anyways, but correct me if I'm wrong there.

This also seems to be a regression introduced with GCC-8.1 since GCC-4.5 to
GCC-7.5 generate the same assembly as for the first and second function and all
version after that including trunk produce different outputs.

[link to godbolt](https://godbolt.org/z/r3vhYbK6o)

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug regression/105126] Optimization regression gcc inserts not needed movsx when using switch statement
  2022-04-01 13:42 [Bug regression/105126] New: Optimization regression gcc inserts not needed movsx when using switch statement andre.schackier at gmail dot com
@ 2022-04-01 15:39 ` marxin at gcc dot gnu.org
  2022-04-04  7:11 ` [Bug middle-end/105126] [9/10/11/12 Regression] " rguenth at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-04-01 15:39 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2022-04-01
           Assignee|unassigned at gcc dot gnu.org      |marxin at gcc dot gnu.org
                 CC|                            |marxin at gcc dot gnu.org

--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
Started with my r8-2897-g02e637d86f9ecb6d, will take a look.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug middle-end/105126] [9/10/11/12 Regression] Optimization regression gcc inserts not needed movsx when using switch statement
  2022-04-01 13:42 [Bug regression/105126] New: Optimization regression gcc inserts not needed movsx when using switch statement andre.schackier at gmail dot com
  2022-04-01 15:39 ` [Bug regression/105126] " marxin at gcc dot gnu.org
@ 2022-04-04  7:11 ` rguenth at gcc dot gnu.org
  2022-04-20 10:18 ` jakub at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-04-04  7:11 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |9.5
           Priority|P3                          |P2

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug middle-end/105126] [9/10/11/12 Regression] Optimization regression gcc inserts not needed movsx when using switch statement
  2022-04-01 13:42 [Bug regression/105126] New: Optimization regression gcc inserts not needed movsx when using switch statement andre.schackier at gmail dot com
  2022-04-01 15:39 ` [Bug regression/105126] " marxin at gcc dot gnu.org
  2022-04-04  7:11 ` [Bug middle-end/105126] [9/10/11/12 Regression] " rguenth at gcc dot gnu.org
@ 2022-04-20 10:18 ` jakub at gcc dot gnu.org
  2022-05-27  9:47 ` [Bug middle-end/105126] [10/11/12/13 " rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-04-20 10:18 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Bet this is related to the unfortunately still not existent type demotion pass
(that would need to be followed by some late type promotion pass before
expansion or before vectorization on the for vectorization only copy of loops).
Or we could just demote switches.
We do some demotions right now solely in the FEs (get_narrower and the like),
which is something that could handle this case, but that wouldn't handle the
case where the promotion is only visible after some propagation etc., and needs
actually analysis of all the case label values (case labels out of bounds need
to be DCEd or if they are ranges, narrowed).

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug middle-end/105126] [10/11/12/13 Regression] Optimization regression gcc inserts not needed movsx when using switch statement
  2022-04-01 13:42 [Bug regression/105126] New: Optimization regression gcc inserts not needed movsx when using switch statement andre.schackier at gmail dot com
                   ` (2 preceding siblings ...)
  2022-04-20 10:18 ` jakub at gcc dot gnu.org
@ 2022-05-27  9:47 ` rguenth at gcc dot gnu.org
  2022-06-28 10:48 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-05-27  9:47 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|9.5                         |10.4

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 9 branch is being closed

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug middle-end/105126] [10/11/12/13 Regression] Optimization regression gcc inserts not needed movsx when using switch statement
  2022-04-01 13:42 [Bug regression/105126] New: Optimization regression gcc inserts not needed movsx when using switch statement andre.schackier at gmail dot com
                   ` (3 preceding siblings ...)
  2022-05-27  9:47 ` [Bug middle-end/105126] [10/11/12/13 " rguenth at gcc dot gnu.org
@ 2022-06-28 10:48 ` jakub at gcc dot gnu.org
  2022-11-28 18:21 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-06-28 10:48 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|10.4                        |10.5

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 10.4 is being released, retargeting bugs to GCC 10.5.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug middle-end/105126] [10/11/12/13 Regression] Optimization regression gcc inserts not needed movsx when using switch statement
  2022-04-01 13:42 [Bug regression/105126] New: Optimization regression gcc inserts not needed movsx when using switch statement andre.schackier at gmail dot com
                   ` (4 preceding siblings ...)
  2022-06-28 10:48 ` jakub at gcc dot gnu.org
@ 2022-11-28 18:21 ` pinskia at gcc dot gnu.org
  2023-01-11 12:36 ` marxin at gcc dot gnu.org
  2023-07-07 10:42 ` [Bug middle-end/105126] [11/12/13/14 " rguenth at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-28 18:21 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note for aarch64, is_bin_1 produces better code on the trunk than is_bin_0.
There is an extra zero extent for is_bin_0 there.

So I suspect this is we get a promotion/demotion pass, it will definitely need
to check some target specific hooks/macros to get the best code generation.
x86_64 might be one of the few targets (left) that demotion makes a difference
while most other targets want promotions really.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug middle-end/105126] [10/11/12/13 Regression] Optimization regression gcc inserts not needed movsx when using switch statement
  2022-04-01 13:42 [Bug regression/105126] New: Optimization regression gcc inserts not needed movsx when using switch statement andre.schackier at gmail dot com
                   ` (5 preceding siblings ...)
  2022-11-28 18:21 ` pinskia at gcc dot gnu.org
@ 2023-01-11 12:36 ` marxin at gcc dot gnu.org
  2023-07-07 10:42 ` [Bug middle-end/105126] [11/12/13/14 " rguenth at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: marxin at gcc dot gnu.org @ 2023-01-11 12:36 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|marxin at gcc dot gnu.org          |unassigned at gcc dot gnu.org
             Status|ASSIGNED                    |NEW

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug middle-end/105126] [11/12/13/14 Regression] Optimization regression gcc inserts not needed movsx when using switch statement
  2022-04-01 13:42 [Bug regression/105126] New: Optimization regression gcc inserts not needed movsx when using switch statement andre.schackier at gmail dot com
                   ` (6 preceding siblings ...)
  2023-01-11 12:36 ` marxin at gcc dot gnu.org
@ 2023-07-07 10:42 ` rguenth at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-07 10:42 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|10.5                        |11.5

--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 10 branch is being closed.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-07-07 10:42 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-01 13:42 [Bug regression/105126] New: Optimization regression gcc inserts not needed movsx when using switch statement andre.schackier at gmail dot com
2022-04-01 15:39 ` [Bug regression/105126] " marxin at gcc dot gnu.org
2022-04-04  7:11 ` [Bug middle-end/105126] [9/10/11/12 Regression] " rguenth at gcc dot gnu.org
2022-04-20 10:18 ` jakub at gcc dot gnu.org
2022-05-27  9:47 ` [Bug middle-end/105126] [10/11/12/13 " rguenth at gcc dot gnu.org
2022-06-28 10:48 ` jakub at gcc dot gnu.org
2022-11-28 18:21 ` pinskia at gcc dot gnu.org
2023-01-11 12:36 ` marxin at gcc dot gnu.org
2023-07-07 10:42 ` [Bug middle-end/105126] [11/12/13/14 " rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).