[Bug tree-optimization/70604] switch statement optimization creates dead code

2016-04-13 Thread jpoimboe at redhat dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70604

Josh Poimboeuf  changed:

   What|Removed |Added

 CC||rguenth at gcc dot gnu.org

--- Comment #4 from Josh Poimboeuf  ---
Richard, just realized you weren't on CC for my response to your question.

[Bug tree-optimization/70604] switch statement optimization creates dead code

2016-04-12 Thread jpoimboe at redhat dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70604

--- Comment #3 from Josh Poimboeuf  ---
Hi Richard, thanks for looking at it!

(In reply to Richard Biener from comment #2)
> Are the cases you still see indirect jumps to only one active case or
> is it just that if()s with multiple cases would have avoided the dead
> code?

I don't quite understand the second part of your question, but maybe this
information will answer it.

With GCC 6 I've only seen one occurrence of this issue, which is the one for
which I posted the assembler and .i file above.  It has an indirect jump which
is hard-coded to use only one entry in the jump table, as shown in the
assembler code above.

Note that the C code has two switch statements, which seem to correspond to the
two "normal" cases of indirect jump table patterns.  But then there's the third
unusual indirect jump, shown above, which also corresponds to one of the two
switch statements -- so there are two jump tables for a single switch
statement, where one of the tables appears to be optimized for a single case. 
Hopefully I'm making sense :-)

With GCC 5, the other occurrences of this issue were very similar, with switch
statements and indirect jumps to a single entry in the jump table.

[Bug tree-optimization/70604] switch statement optimization creates dead code

2016-04-12 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70604

Richard Biener  changed:

   What|Removed |Added

   Keywords||missed-optimization
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2016-04-12
 CC||jamborm at gcc dot gnu.org
  Component|c   |tree-optimization
 Ever confirmed|0   |1

--- Comment #2 from Richard Biener  ---
For GCC 6 stronger value-numbering might have fixed most cases.

Are the cases you still see indirect jumps to only one active case or
is it just that if()s with multiple cases would have avoided the dead
code?

I can see

  :
  _139 = [(void *)cmd_84(D) + 930B];
  _141 = conn_140(D)->sess;
  _142 = _141->se_sess;
  _143 = _84(D)->se_cmd;
  transport_init_se_cmd (_143, _ops, _142, 0, 3, 32, _139);
  target_get_sess_cmd (_143, 1);
  switch (_58) , case 1: , case 2: , case 3: ,
case 4: , case 5: , case 6: , case 7: >

:
  goto  ();

:
  goto  ();

:
  goto  ();

:
  goto  ();

:
  goto  ();

:
  _146 = (int) _58;
  printk ("\13Unknown iSCSI TMR Function: 0x%02x\n", _146);
  _351 = iscsit_add_reject_from_cmd (cmd_84(D), 10, 1, buf_55(D)); [tail call]
  goto ;

:

  # prephitmp_14 = PHI <1(18), 2(11), 3(12), 4(13), 5(14), 6(15), 7(16)>
:


with the default case looping back.  switch conversion should probably handle
this but is run too early.  OTOH it seems to be confused by the default
case not falling thru, failing to see the "simple" transform to a

  if (... >= 1 && ... <= 7)
   ;
  else
   old default;

beginning to process the following SWITCH statement
(drivers/target/iscsi/iscsi_target.c:1807) : ---
switch (_74) , case 1: , case 2: , case 3: ,
case 4: , case 5: , case 6: , case 7: >

Bailing out - no common successor to all case label target blocks found

beginning to process the following SWITCH statement
(drivers/target/iscsi/iscsi_target.c:1866) : ---
switch (_74) , case 1: , case 2 ... 5: , case 6:
, case 7: , case 8: >

Bailing out - no common successor to all case label target blocks found



Not sure what the other cases are.