This is a follow-up to D120386 where we enabled interchange to get the optimal access pattern for multi-level loopnests. But currently loop interchange fails to interchange multi-level loopnests that have reduction operations inside the loopnest. This patch enables interchange of reduction loops with multi-level loopnests, for example the following loopnest should be interchanged three times to get the optimal access pattern:
; Triply nested loop with reduction, should be able to do interchange three times ; to get the ideal access pattern. unsigned f(int e[100][100][100], int f[100][100][100]) { unsigned x = 0; for (int a = 0; a < 100; a++) { for (int b = 0; b < 100; b++) { for (int c = 0; c < 100; c++) { x += e[c][b][a]; } } } return x; }
Currently interchange only supports reduction loops within 2-level loopnests. For loopnests with more than 2-levels like the case above, (after interchanging the b-loop and c-loop) the pass cannot recognize reduction phis and would bail out. This patch adds capability to recognize reduction phis for multi-level loopnests.
[Nit] innermost could be considered a single word