public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/95208] New: missed switch optimization as bit test
@ 2020-05-19 13:42 nathan at gcc dot gnu.org
  2020-05-20 11:02 ` [Bug middle-end/95208] " marxin at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: nathan at gcc dot gnu.org @ 2020-05-19 13:42 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95208
           Summary: missed switch optimization as bit test
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nathan at gcc dot gnu.org
  Target Milestone: ---

Created attachment 48565
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48565&action=edit
The if case is optimized better

This comes from libcpp/lex.c's raw string lexer.  We're testing whether a
character falls into a particular set of values.  The switch is emitted as the
usual dispatch table.  The if case, after range checking, turns into
'if ((1ul << (c - BASE)) & MAGIC_VALUE)'  Which is somewhat better.  Why
doesn't the switch form do that?

_Z3bazc:
.LFB1:
        .cfi_startproc
        leal    -97(%rdi), %eax
        cmpb    $29, %al
        jbe     .L7
        subl    $33, %edi
        cmpb    $62, %dil
        ja      .L6
        movabsq $8646911282403868279, %rax
        btq     %rdi, %rax
        jc      .L7
.L6:
        ret
        .p2align 4,,10
        .p2align 3
.L7:
        jmp     _Z3barv
        .cfi_endproc

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

* [Bug middle-end/95208] missed switch optimization as bit test
  2020-05-19 13:42 [Bug middle-end/95208] New: missed switch optimization as bit test nathan at gcc dot gnu.org
@ 2020-05-20 11:02 ` marxin at gcc dot gnu.org
  2021-07-21  0:14 ` pinskia at gcc dot gnu.org
  2021-12-07  8:15 ` marxin at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: marxin at gcc dot gnu.org @ 2020-05-20 11:02 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2020-05-20
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
Looking at the dump files, we select a jump table:

switch (c_2(D)) <default: <L88> [67.00%], case 33 ... 35: <L0> [33.00%], case
37 ... 39: <L0> [33.00%], case 42 ... 63: <L0> [33.00%], case 65 ... 91: <L0>
[33.00%], case 93 ... 95: <L0> [33.00%], case 97 ... 126: <L0> [33.00%]>

;; GIMPLE switch case clusters: JT(values:88 comparisons:12 range:94 density:
12.77%):33-126 

We prefer a smaller number of clusters (in this case) one because we don't have
to build a decision tree on top of them. In this case one can't handle all in
of bit test as the range of values is >= 64.

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

* [Bug middle-end/95208] missed switch optimization as bit test
  2020-05-19 13:42 [Bug middle-end/95208] New: missed switch optimization as bit test nathan at gcc dot gnu.org
  2020-05-20 11:02 ` [Bug middle-end/95208] " marxin at gcc dot gnu.org
@ 2021-07-21  0:14 ` pinskia at gcc dot gnu.org
  2021-12-07  8:15 ` marxin at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-21  0:14 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This looks fixed in GCC 11.

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

* [Bug middle-end/95208] missed switch optimization as bit test
  2020-05-19 13:42 [Bug middle-end/95208] New: missed switch optimization as bit test nathan at gcc dot gnu.org
  2020-05-20 11:02 ` [Bug middle-end/95208] " marxin at gcc dot gnu.org
  2021-07-21  0:14 ` pinskia at gcc dot gnu.org
@ 2021-12-07  8:15 ` marxin at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-12-07  8:15 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED

--- Comment #3 from Martin Liška <marxin at gcc dot gnu.org> ---
Fixed since r11-5049-g5e303cdee1ff01e4.

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

end of thread, other threads:[~2021-12-07  8:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-19 13:42 [Bug middle-end/95208] New: missed switch optimization as bit test nathan at gcc dot gnu.org
2020-05-20 11:02 ` [Bug middle-end/95208] " marxin at gcc dot gnu.org
2021-07-21  0:14 ` pinskia at gcc dot gnu.org
2021-12-07  8:15 ` marxin 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).