The following patch improves the fix for PR69719 after spending another hour in trying to understand that code (and revisiting the original patch postings). The code assumes that dr_a1 is left of dr_a2 which is not always the case (sorting doesn't guarantee that), if that's not the case we can observe negative differences as seen in the PR. There are downstream tests that also rely on that ordering so we'd better fix the ordering rather than just computing the absolute of the diff.
Now, I still don't get how validity can be guaranteed given that dr_a1 seg_len might be larger than diff and I don't get how the segment length of dr_b can play any role in validating either. But without a testcase it's not the time to kill this code and replace it by something more obvious (I do have some more obvious solution though). Bootstrapped and tested on x86_64-unknown-linux-gnu, applied. Richard. 2016-02-10 Richard Biener <rguent...@suse.de> PR tree-optimization/69719 * tree-vect-data-refs.c (vect_prune_runtime_alias_test_list): Adjust previous fix by ensuring that dr_a1 is left of dr_a2. Index: gcc/tree-vect-data-refs.c =================================================================== --- gcc/tree-vect-data-refs.c (revision 233261) +++ gcc/tree-vect-data-refs.c (working copy) @@ -3081,9 +3081,12 @@ vect_prune_runtime_alias_test_list (loop || !tree_fits_shwi_p (dr_a2->offset)) continue; + /* Make sure dr_a1 starts left of dr_a2. */ + if (tree_int_cst_lt (dr_a2->offset, dr_a1->offset)) + std::swap (*dr_a1, *dr_a2); + unsigned HOST_WIDE_INT diff - = absu_hwi (tree_to_shwi (dr_a2->offset) - - tree_to_shwi (dr_a1->offset)); + = tree_to_shwi (dr_a2->offset) - tree_to_shwi (dr_a1->offset); /* Now we check if the following condition is satisfied: