Index: llvm/lib/Transforms/Scalar/LoopInterchange.cpp =================================================================== --- llvm/lib/Transforms/Scalar/LoopInterchange.cpp +++ llvm/lib/Transforms/Scalar/LoopInterchange.cpp @@ -1113,18 +1113,19 @@ static bool isProfitableForVectorization(unsigned InnerLoopId, unsigned OuterLoopId, CharMatrix &DepMatrix) { - // TODO: Improve this heuristic to catch more cases. - // If the inner loop is loop independent or doesn't carry any dependency it is - // profitable to move this to outer position. for (auto &Row : DepMatrix) { - if (Row[InnerLoopId] != 'S' && Row[InnerLoopId] != 'I') - return false; - // TODO: We need to improve this heuristic. + // If the inner loop is loop independent or doesn't carry any dependency it is + // not profitable to move this to outer position, since we are likely able to do + // inner loop vectorization already. + if (Row[InnerLoopId] == 'I' || Row[InnerLoopId] == '=' ) + return false; + // If the outer loop is not loop independent it is not not profitable to move this + // to inner position, since doing so would not enable inner loop parallelism. if (Row[OuterLoopId] != '=') return false; } - // If outer loop has dependence and inner loop is loop independent then it is - // profitable to interchange to enable parallelism. + // If inner loop has dependence and outer loop is loop independent then it is + // profitable to interchange to enable inner loop parallelism. // If there are no dependences, interchanging will not improve anything. return !DepMatrix.empty(); }