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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |10.0
   Last reconfirmed|2015-12-28 00:00:00         |2021-6-4

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
>From *.iftoswitch on the trunk:
;;  Canonical GIMPLE case clusters: 0 1 2 3 4 5


So I looked and this is fixed but not for the low if count.
Take:
#define B(y) void f##y(void);
#define B10(y)  B(y##0)  B(y##1)  B(y##2) \
                B(y##3)  B(y##4)  B(y##5) \
                B(y##6)  B(y##7)  B(y##8) \
                B(y##9)
#define B100(y)  B10(y##0)  B10(y##1)  B10(y##2) \
                 B10(y##3)  B10(y##4)  B10(y##5) \
                 B10(y##6)  B10(y##7)  B10(y##8) \
                 B10(y##9)

B10(1)
B100(1)

#define A(y) else if (x == y) f##y();
#define A10(y)  A(y##0) \
                A(y##1) \
                A(y##2) \
                A(y##3) \
                A(y##4) \
                A(y##5) \
                A(y##6) \
                A(y##7) \
                A(y##8) \
                A(y##9)

#define A100(y) A10(y##0)  \
                A10(y##1) \
                A10(y##2) \
                A10(y##3) \
                A10(y##4) \
                A10(y##5) \
                A10(y##6) \
                A10(y##7) \
                A10(y##8) \
                A10(y##9)

void f10(int x)
{
  if (0) ;
  A10(1)
}
void f100(int x)
{
  if (0) ;
  A100(1)
}

--- CUT ----
f100 is converted while f10 is not.  This is a heuristics at work to see if it
is better as a jump table vs if statements.

https://godbolt.org/z/ofWGb5aKn for reference.

Clang decides (I don't know if they lower switches back to if statements) to do
the switch for all cases.

So we can close this as fixed.

Reply via email to