[LoopInterchange] Replace tightly-nesting-ness check with the one from `LoopNest`
authorTa-Wei Tu <tu.da.wei@gmail.com>
Mon, 8 Mar 2021 03:35:35 +0000 (11:35 +0800)
committerTa-Wei Tu <tu.da.wei@gmail.com>
Mon, 8 Mar 2021 03:36:08 +0000 (11:36 +0800)
commitdf9158c9a45a6902c2b0394f9bd6512e3e441f31
tree6f006a050836a1f9694a96231a2c6dd6f6cb80bb
parent7514f1a312751089ef25df02eaf638a5a5192da3
[LoopInterchange] Replace tightly-nesting-ness check with the one from `LoopNest`

The check `tightlyNested()` in `LoopInterchange` is similar to the one in `LoopNest`.
In fact, the former misses some cases where loop-interchange is not feasible and results in incorrect behaviour.
Replacing it with the much robust version provided by `LoopNest` reduces code duplications and fixes https://bugs.llvm.org/show_bug.cgi?id=48113.

`LoopInterchange` has a weaker definition of tightly or perfectly nesting-ness than the one implemented in `LoopNest::arePerfectlyNested()`.
Therefore, `tightlyNested()` is instead implemented with `LoopNest::checkLoopsStructure` and additional checks for unsafe instructions.

Reviewed By: Whitney

Differential Revision: https://reviews.llvm.org/D97290
llvm/include/llvm/Analysis/LoopNestAnalysis.h
llvm/lib/Analysis/LoopNestAnalysis.cpp
llvm/lib/Transforms/Scalar/LoopInterchange.cpp
llvm/test/Transforms/LoopInterchange/pr48113.ll [new file with mode: 0644]