https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68953
--- Comment #5 from vries at gcc dot gnu.org --- Created attachment 38207 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=38207&action=edit demonstrator patch In add_pdr_constraints, for the EXTRADIM=0 case we have: ... accesses: { S_4[i1, i2] -> [1, 1 + i1] } subscript_sizes: { [1, i1] : i1 >= 0 and i1 <= 3 } intersection: { S_4[i1, i2] -> [1, 1 + i1] : i1 >= -1 and i1 <= 2 } ... but for the EXTRADIM=1 case, we have: ... accesses: { S_4[i1, i2] -> [1, 0, 1 + i1] } subscript_sizes: { [1, i1, 0] : i1 >= 0 and i1 <= 3 } intersection: { S_4[-1, i2] -> [1, 0, 0] } ... Actually, the accesses are ordered: [alias set, last subscript, first subscript] and the subscript sizes are ordered: [alias set range, first subscript range, last subscript range] and that explains why intersection gives unintended results. The patch changes the order of the subscript functions (that was the easiest for me to implement) to: [alias set, first subscript, last subscript] and we get a more reasonable intersection (similar to the EXTRADIM=0 case): ... accesses: { S_4[i1, i2] -> [1, 1 + i1, 0] } subscript_sizes: { [1, i1, 0] : i1 >= 0 and i1 <= 3 } intersection: { S_4[i1, i2] -> [1, 1 + i1, 0] : i1 >= -1 and i1 <= 2 } ... and consequently, correct dependences, and the wrong-code issue is fixed. Atm though I've got no clue about the overall effect of this change, or what the actual fix should look like.