This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Dead code elimination PROBLEM


Hi PPL i developed a plugin that  produces the following gimple

test ()
{
  int selected_fnc_var_.3;
  int random_Var.2;
  int D.2363;
  int _1;

  <bb 2>:
  random_Var.2_2 = rand ();
  selected_fnc_var_.3_3 = random_Var.2_2 %[fl] 5;
  if (selected_fnc_var_.3_3 == 4) goto <L7>;
  if (selected_fnc_var_.3_3 == 3) goto <L6>;
  if (selected_fnc_var_.3_3 == 2) goto <L5>;
  if (selected_fnc_var_.3_3 == 1) goto <L4>;
  if (selected_fnc_var_.3_3 == 0) goto <L3>;
<L7>:
  _1 = f.clone.4 ("t", "t");
  goto <L8>;
<L6>:
  _1 = f.clone.3 ("t", "t");
  goto <L8>;
<L5>:
  _1 = f.clone.2 ("t", "t");
  goto <L8>;
<L4>:
  _1 =f.clone.1 ("t", "t");
  goto <L8>;

<L8>:
  if (_1 != 0)
    goto <bb 3>;
  else
    goto <bb 4>;

  <bb 3>:
  __builtin_puts (&" f success "[0]);
  goto <bb 5>;

  <bb 4>:
  __builtin_puts (&" f failed "[0]);

  <bb 5>:
  return;

}

with this final code

00000000004005c6 <test>:
  4005c6:    55                       push   %rbp
  4005c7:    48 89 e5                 mov    %rsp,%rbp
  4005ca:    53                       push   %rbx
  4005cb:    48 83 ec 08              sub    $0x8,%rsp
  4005cf:    e8 6c fe ff ff           callq  400440 <rand@plt>
  4005d4:    89 d9                    mov    %ebx,%ecx
  4005d6:    c1 f9 1f                 sar    $0x1f,%ecx
  4005d9:    89 d8                    mov    %ebx,%eax
  4005db:    31 c8                    xor    %ecx,%eax
  4005dd:    ba 67 66 66 66           mov    $0x66666667,%edx
  4005e2:    f7 e2                    mul    %edx
  4005e4:    89 d0                    mov    %edx,%eax
  4005e6:    d1 e8                    shr    %eax
  4005e8:    31 c8                    xor    %ecx,%eax
  4005ea:    89 c2                    mov    %eax,%edx
  4005ec:    c1 e2 02                 shl    $0x2,%edx
  4005ef:    01 c2                    add    %eax,%edx
  4005f1:    89 d8                    mov    %ebx,%eax
  4005f3:    29 d0                    sub    %edx,%eax
  4005f5:    83 f8 04                 cmp    $0x4,%eax
  4005f8:    75 32                    jne    40062c <test+0x66>
  4005fa:    83 f8 03                 cmp    $0x3,%eax
  4005fd:    74 2d                    je     40062c <test+0x66>
  4005ff:    83 f8 02                 cmp    $0x2,%eax
  400602:    74 28                    je     40062c <test+0x66>
  400604:    83 f8 01                 cmp    $0x1,%eax
  400607:    74 23                    je     40062c <test+0x66>
  400609:    85 c0                    test   %eax,%eax
  40060b:    74 1f                    je     40062c <test+0x66>
  40060d:    be bc 09 40 00           mov    $0x4009bc,%esi
  400612:    bf c6 09 40 00           mov    $0x4009c6,%edi
  400617:    e8 7d 02 00 00           callq  400899 <f.clone.4>
  40061c:    85 c0                    test   %eax,%eax
  40061e:    75 0c                    jne    40062c <test+0x66>
  400620:    bf d0 09 40 00           mov    $0x4009d0,%edi
  400625:    e8 e6 fd ff ff           callq  400410 <puts@plt>
  40062a:    eb 0a                    jmp    400636 <test+0x70>
  40062c:    bf e8 09 40 00           mov    $0x4009e8,%edi
  400631:    e8 da fd ff ff           callq  400410 <puts@plt>
  400636:    48 83 c4 08              add    $0x8,%rsp
  40063a:    5b                       pop    %rbx
  40063b:    5d                       pop    %rbp
  40063c:    c3                       retq


from this gimple

test(){

int D.2363;
  int _1;

  <bb 2>:
  _1 = f("t", "t");
  if (_1 != 0)
    goto <bb 3>;
  else
    goto <bb 4>;

  <bb 3>:
  __builtin_puts (&" f "[0]);
  goto <bb 5>;

  <bb 4>:
  __builtin_puts (&" f "[0]);

  <bb 5>:
  return;
}

as you can see in the dis output code, its only make call to f.clone.4 ( callq 400899 <f.clone.4> ), i suppose is the dead code elimination pass is the responsable of this action, i tryed to disable it using -O0 compilation option but without success. my question is how can i make the compiler produce the final code without deleting those dead codes portion ( do i need to make any kind of PHI nodes in the labels to achive that, if so how could i do that ? )

thanks in advance


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]