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

--- Comment #1 from Marc Glisse <glisse at gcc dot gnu.org> ---
(In reply to Renlin Li from comment #0)
>   char array[] = "abc";
>   return __builtin_strlen (array);

There are DUPs for this part.

> int hallo ();
> int dummy ()
> {
>   char array[] = "abc";
>   return hallo () + __builtin_strlen (array);
> }
> 
> the __builtin_strlen is not fold into a const as in foo () above. Presumably,
> gcc is too conservative about what hallo () function can do. By adding a
> pure attribute to hallo (), gcc will generate optimal code.

Here it depends if we produce:

size_t tmp1=hallo();
size_t tmp2=strlen(array);
return tmp1+tmp2;

or use the reverse order for tmp1 and tmp2. Currently we evaluate a before b in
a+b, this example seems to suggest that when one sub-expression is pure and not
the other, it would make sense to evaluate the pure one first (assuming we can
determine that information early enough). It also depends where the C++
proposal about order of evaluation is going...

Or we could do like clang and improve alias analysis. We should know that array
doesn't escape and thus that hallo() cannot write to it.

Reply via email to