+2017-12-19 Jakub Jelinek <jakub@redhat.com>
+
+ PR tree-optimization/83444
+ * tree-ssa-strlen.c (strlen_check_and_optimize_stmt): For the
+ character load case, if get_stridx on MEM_REF's operand doesn't
+ look usable, retry with get_addr_stridx.
+
2017-12-19 Alexandre Oliva <aoliva@redhat.com>
PR debug/83422
2017-12-19 Jakub Jelinek <jakub@redhat.com>
+ PR tree-optimization/83444
+ * gcc.dg/strlenopt-38.c: New test.
+
PR testsuite/83454
* gcc.dg/tree-ssa/cswtch-4.c: Require nonpic effective target.
* gcc.dg/tree-ssa/cswtch-5.c: Likewise.
{
tree off = integer_zero_node;
unsigned HOST_WIDE_INT coff = 0;
- int idx = -1;
+ int idx = 0;
tree rhs1 = gimple_assign_rhs1 (stmt);
if (code == MEM_REF)
{
idx = get_stridx (TREE_OPERAND (rhs1, 0));
- off = TREE_OPERAND (rhs1, 1);
+ if (idx > 0)
+ {
+ strinfo *si = get_strinfo (idx);
+ if (si
+ && si->nonzero_chars
+ && TREE_CODE (si->nonzero_chars) == INTEGER_CST
+ && (wi::to_widest (si->nonzero_chars)
+ >= wi::to_widest (off)))
+ off = TREE_OPERAND (rhs1, 1);
+ else
+ /* This case is not useful. See if get_addr_stridx
+ returns something usable. */
+ idx = 0;
+ }
}
- else
+ if (idx <= 0)
idx = get_addr_stridx (rhs1, NULL_TREE, &coff);
if (idx > 0)
{