This is the mail archive of the gcc-patches@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]

Re: [PATCH] minor tweak to complete strlen fix for PR83501


On 01/03/2018 02:29 PM, Martin Sebor wrote:
> Prathamesh's fix restores the optimization for the test case
> reported in the bug (thanks!) but it isn't sufficient to bring
> GCC 8 completely up to par with 7.  Prior GCC versions are able
> to compute the string length in the test case below but GCC 8
> cannot.
> 
>   char d[8];
>   const char s[] = "1234567";
> 
>   void f (void)
>   {
>     __builtin_strcpy (d, s);
>     if (__builtin_strlen (d) != sizeof s - 1)
>       __builtin_abort ();
>   }
> 
> The attached patch slightly tweaks Prathamesh's patch to also
> handle the case above.  There still are outstanding cases where
> folding into MEM_REF defeats the strlen pass (I've raised
> a couple of new bugs to track those I noticed today) but, AFAICT,
> those aren't recent regressions so they can be dealt with later
> and separately.
> 
> Martin
> 
> PS I've renamed the function because I had initially thought it
> also needed to handle PHIs that refer to strings of the same
> length (and there isn't necessarily one "right" string to return)
> but then realized that the lack of that handling isn't part of
> the regression so I didn't include it but kept the new return
> type and name.  When the pass is enhanced to handle PHIs and
> some of the other cases it doesn't handle the function won't
> need to change.
> 
> gcc-83501.diff
> 
> 
> PR tree-optimization/83501 - strlen(a) not folded after strcpy(a, ...)
> 
> gcc/ChangeLog:
> 
> 	PR tree-optimization/83501
> 	* tree-ssa-strlen.c (get_string_cst): Rename...
> 	(get_strlen): ...to this.  Handle global constants.
> 	(handle_char_store): Adjust.
> 
> gcc/testsuite/ChangeLog:
> 
> 	PR tree-optimization/83501
> 	* gcc.dg/strlenopt-39.c: New test.
OK.
jeff


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