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

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

--- Comment #7 from Martin Liška <marxin at gcc dot gnu.org> ---
So what happens with the current master: we first convert the if-else-if series
to switch in iftoswitch pass:

  dst_port_5 = MEM[(const uint16_t *)data_3(D) + 64B];
  switch (dst_port_5) <default: <L25> [INV], case 1: <L22> [INV], case 2: <L23>
[INV], case 3: <L24> [INV], case 15: <L17> [INV], case 23: <L18> [INV], case
42: <L21> [INV], case 45: <L20> [INV], case 47: <L19> [INV]>

  <bb 3> :
<L17>:
  // predicted unlikely by early return (on trees) predictor.
  goto <bb 11>; [INV]

  <bb 4> :
<L18>:
  // predicted unlikely by early return (on trees) predictor.
  goto <bb 11>; [INV]

  <bb 5> :
<L19>:
  // predicted unlikely by early return (on trees) predictor.
  goto <bb 11>; [INV]

  <bb 6> :
<L20>:
  // predicted unlikely by early return (on trees) predictor.
  goto <bb 11>; [INV]

  <bb 7> :
<L21>:
  // predicted unlikely by early return (on trees) predictor.
  goto <bb 11>; [INV]

  <bb 8> :
<L22>:
  // predicted unlikely by early return (on trees) predictor.
  goto <bb 11>; [INV]

  <bb 9> :
<L23>:
  // predicted unlikely by early return (on trees) predictor.
  goto <bb 11>; [INV]

  <bb 10> :
<L24>:
  // predicted unlikely by early return (on trees) predictor.

  <bb 11> :
  # _2 = PHI <1(4), 1(5), 1(3), 1(10), 1(9), 1(8), 1(7), 1(6), 0(2)>

then convert tree-switch-conversion which prefers bit test if possible.
However, the CFG is not collapsed and thus it fails due to:

bool
bit_test_cluster::is_beneficial (unsigned count, unsigned uniq)
{
  return (((uniq == 1 && count >= 3)
           || (uniq == 2 && count >= 5)
           || (uniq == 3 && count >= 6)));
}

as count == 7. and so tree-switch-conversion happens. So one can mitigate that
with:
1) use switch statement instead of if series
2) reduce -param=switch-conversion-max-branch-ratio= that will not create so
big CSWTCH array
3) disable tree-switch-conversion pass

Reply via email to