This avoids matching strlen to a pointer result, avoiding ICEing
because of an integer adjustment using PLUS_EXPR on pointers.
2022-06-01 Richard Biener <rguenther@suse.de>
PR tree-optimization/105786
* tree-loop-distribution.cc
(loop_distribution::transform_reduction_loop): Only do strlen
replacement for integer type reductions.
* gcc.dg/torture/pr105786.c: New testcase.
--- /dev/null
+/* { dg-do compile } */
+
+void sink(const char*);
+static const char *a;
+int main()
+{
+ const char *b = a;
+ for (int i = 0; i < 2; ++i)
+ while (*b++)
+ ;
+ sink(b);
+ return 0;
+}
/* Handle strlen like loops. */
if (store_dr == NULL
&& integer_zerop (pattern)
+ && INTEGRAL_TYPE_P (TREE_TYPE (reduction_var))
&& TREE_CODE (reduction_iv.base) == INTEGER_CST
&& TREE_CODE (reduction_iv.step) == INTEGER_CST
&& integer_onep (reduction_iv.step))