The following side-steps a possible issue with the evolution_function_is_affine_multivariate_p predicate by guarding the call to analyze_subscript_affine_affine in analyze_miv_subscript in the same way as the call from analyze_siv_subscript.
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk. Richard. 2018-11-15 Richard Biener <rguent...@suse.de> PR middle-end/87917 * tree-data-ref.c (analyze_miv_subscript): Guard calls to analyze_subscript_affine_affine properly. * gcc.dg/tree-ssa/pr87917.c: New testcase. Index: gcc/tree-data-ref.c =================================================================== --- gcc/tree-data-ref.c (revision 266145) +++ gcc/tree-data-ref.c (working copy) @@ -3994,9 +3993,9 @@ analyze_miv_subscript (tree chrec_a, dependence_stats.num_miv_independent++; } - else if (evolution_function_is_affine_multivariate_p (chrec_a, loop_nest->num) + else if (evolution_function_is_affine_in_loop (chrec_a, loop_nest->num) && !chrec_contains_symbols (chrec_a) - && evolution_function_is_affine_multivariate_p (chrec_b, loop_nest->num) + && evolution_function_is_affine_in_loop (chrec_b, loop_nest->num) && !chrec_contains_symbols (chrec_b)) { /* testsuite/.../ssa-chrec-35.c Index: gcc/testsuite/gcc.dg/tree-ssa/pr87917.c =================================================================== --- gcc/testsuite/gcc.dg/tree-ssa/pr87917.c (nonexistent) +++ gcc/testsuite/gcc.dg/tree-ssa/pr87917.c (working copy) @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -ftree-loop-distribute-patterns -ftrapv -fno-tree-fre" } */ + +void foo(int x[]) +{ + int i, j; + + for (i = 0; i < 2; i++) + for (j = 0; j < 2; j++) + { + x[i] = x[i*j]; + x[i] = x[i*j]; + } +}