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

            Bug ID: 117352
           Summary: switch bit test conversion makes comparison code worse
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ak at gcc dot gnu.org
  Target Milestone: ---

With the change in PR117091 that makes switch bit test conversion more
aggressive
I see a failure in gcc.dg/pr21643.c which checks for tree reassoc happening.
I fixed the the test by using -fno-bit-tests.

However this makes the generated code on aarch64 worse:

int
f1 (unsigned char c)
{
  if (c == 0x22 || c == 0x20 || c < 0x20)
    return 1;
  return 0;
}

Before (with -fno-bit-tests or without PR117091 change)

f1:
.LFB0:
        and     w0, w0, 255
        mov     w1, 32
        cmp     w0, 34
        ccmp    w0, w1, 0, ne
        cset    w0, ls
        ret


After:

f1:
.LFB0:
        and     w0, w0, 255
        mov     x1, -281449206906881
        movk    x1, 0x0, lsl 48
        cmp     w0, 35
        lsr     x0, x1, x0
        and     w0, w0, 1
        csel    w0, w0, wzr, cc
        ret

So I guess tree-reassoc needs to learn to handle bit test switch code better?

Reply via email to