loongson-community / gcc

GCC source tree for Loongson
GNU General Public License v2.0
17 stars 1 forks source link

[tree-ssa-strlen] missing strlen optimization for strcmp of unequal strings #15

Open xiangzhai opened 6 years ago

xiangzhai commented 6 years ago

Hi fellows,

As PR83026 mentioned: Testcase:

$ cat c.c
void g (const char *a, const char *b)
{
  if (__builtin_strlen (a) == __builtin_strlen (b))
    return;

  if (!__builtin_strcmp (a, b))
    __builtin_abort ();
}

GCC 5.5 and 8.x failed to fold:

if (!__builtin_strcmp (a, b))
    __builtin_abort ();

might be optimized to:

<bb 4> [count: 0]:
  __builtin_abort ();

Without:

<bb 3> [local count: 7903]:
  _3 = __builtin_strcmp (a_5(D), b_6(D));
  if (_3 == 0)
    goto <bb 4>; [0.04%]
  else
    goto <bb 5>; [99.96%]

Qing Zhao is on it :+1:

Regards, Leslie Zhai