diff --git a/trans-array.c b/trans-array.c index 1a86ae6..0c1dc89 100644 --- a/trans-array.c +++ b/trans-array.c @@ -645,6 +645,7 @@ void gfc_add_ss_to_loop (gfc_loopinfo * loop, gfc_ss * head) { gfc_ss *ss; + gfc_loopinfo *nested_loop; if (head == gfc_ss_terminator) return; @@ -654,6 +655,21 @@ gfc_add_ss_to_loop (gfc_loopinfo * loop, gfc_ss * head) ss = head; for (; ss && ss != gfc_ss_terminator; ss = ss->next) { + if (ss->nested_ss) + { + nested_loop = ss->nested_ss->loop; + + /* More than one ss can belong to the same loop. Hence, we add the + loop to the chain only if it is different from the previously + added one, to avoid duplicate nested loops. */ + if (nested_loop != loop->nested) + { + gcc_assert (nested_loop->next == NULL); + nested_loop->next = loop->nested; + loop->nested = nested_loop; + } + } + if (ss->next == gfc_ss_terminator) ss->loop_chain = loop->ss; else diff --git a/trans.h b/trans.h index 0608879..0549aa7 100644 --- a/trans.h +++ b/trans.h @@ -279,6 +279,9 @@ typedef struct gfc_loopinfo /* The SS describing the temporary used in an assignment. */ gfc_ss *temp_ss; + /* Chain of nested loops. */ + struct gfc_loopinfo *nested, *next; + /* The scalarization loop index variables. */ tree loopvar[GFC_MAX_DIMENSIONS];