[polly] [polly] Add profitability check for expanded region. (PR #96548)
Huihui Zhang via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 26 16:54:30 PDT 2024
================
@@ -1621,6 +1626,12 @@ void ScopDetection::findScops(Region &R) {
if (!ExpandedR)
continue;
+ if (!isRegionExpansionProfitable(*ExpandedR, LI)) {
+ removeCachedResults(*ExpandedR);
+ delete ExpandedR;
----------------
huihzhang wrote:
Actually, region expansion profitability check should be done at the completion of `expandRegion`.
Because expanding a region to merge adjacent loops may involve multiple steps: 1) expand to include the exit block of current region, this added block may happen to be the preheader block of the next loop to be merged; 2) expand again to include all the blocks of the next loop; 3) repeat step1 and step2, or add other blocks from given CFG.
During the first expansion, the extra block added does not belong to any loops of the expandedRegion, but is actually the preheader block of the adjacent loop to be merged. Then the loop invariant loads for the next loop is going to cause the very first expansion to fail. Eventually region expansion will fail to merge with the adjacent loop, which should have been merged at the second expansion.
test/CodeGen/region_expansion_profitability_check_loopfusion_1.ll added can be used to reproduce this issue.
https://github.com/llvm/llvm-project/pull/96548
More information about the llvm-commits
mailing list