This is yet another attempt to fix tightlyNested().
Add checks in tightlyNested() for the inner loop exit block,
such that 1) if there is control-flow divergence in between the inner
loop exit block and the outer loop latch, or 2) if the inner loop exit
block contains unsafe instructions, tightlyNested() returns false.
The reasoning behind is that after interchange, the original inner loop
exit block, which was part of the outer loop, would be put into the new
inner loop, and will be executed different number of times before and
after interchange. Thus it should be dealt with appropriately.
For now tests are not provided, and the tests provided in the following patches
https://reviews.llvm.org/D96708 and https://reviews.llvm.org/D91682
are appropriate tests, where tightlyNested() previously returns true and will return
false after this patch.
Apart from that, this patch does not fail any of the existing regression tests.
This test comes from https://reviews.llvm.org/D96708:
#include <stdio.h> static long int i,j,k=3,m=3; unsigned long int x[50]; long double a[50][50]; int main() { for (i=0; i<50; i++) for (j=0; j<50; j++) a[i][j]=i; for (i=0; i<50; i++) x[i]=1; j=0; for(i=40;i>1;i--) { k=20; while(k++<40) x[k]=x[j]%40; a[i][i]+=a[i][j]+a[j][i]; for(m=9;;) if (--m<5) break; } for (i=0; i<50; i++) for (j=0; j<50; j++) printf("a:%ld %5.5Le \n",i,a[i][j]); return 0; }
This test comes from https://reviews.llvm.org/D91682:
char a; int b[][2]; char c[][9]; int h() { for (; f <= 2; f++) { for (int j = 0; j <= 2; j++) { b[j][1] = c[j][f]; } if (a) } return 0; }