At least on SH and r210026 the following: extern "C" const char* strchr (const char*,int); const char* test (const char* x) { return strrchr (x, 0); } does not get converted to a strlen (x). It seems that tree-ssa-strlen is trying to do something but always fails.
1) your testcase uses strrchr rather than strchr 2) why do you think it is desirable to convert strchr (x, 0) to x + strlen (x)? Unless you have good library implementation for the latter and bad for the former, strchr (x, 0) should be a win. What the strlen pass does is that if you e.g. use strchr (x, 0) or strlen (x) several times when the lengths of the strings actually can't change in between, it can avoid the second and following call. And, it is able to deal even with strlen (x) used in one place and strchr (x, 0) in another or vice versa etc. (plus various other optimizations).
(In reply to Jakub Jelinek from comment #1) > 1) your testcase uses strrchr rather than strchr Sorry, typo/pasto. It was meant to be "strchr". > 2) why do you think it is desirable to convert strchr (x, 0) to x + strlen > (x)? On SH we have a builtin strlen implementation. I was just expecting strchr (x, 0) to utilize it, that's all. > Unless you have good library implementation for the latter and bad for the > former, strchr (x, 0) should be a win. > What the strlen pass does is that if you e.g. use strchr (x, 0) or strlen > (x) several times when the lengths of the strings actually can't change in > between, it can avoid the second and following call. And, it is able to > deal even with strlen (x) used in one place and strchr (x, 0) in another or > vice versa etc. (plus various other optimizations). Ah, thanks for the explanation. BTW, are there any plans to add true builtin strchr support so that it can be expanded by the target code in the same way as strlen?
Just for reference https://gcc.gnu.org/ml/gcc-patches/2016-04/msg00870.html
See bug 32650 also.
https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=240568
Fixed in r240568.