Skip to content

Commit

Permalink
[LoopUnroll] Disable loop unroll when user explicitly asks for unroll…
Browse files Browse the repository at this point in the history
…-and-jam

If a loop isn't forced to be unrolled, we want to avoid unrolling it when there
is an explicit unroll-and-jam pragma. This is to prevent automatic unrolling
from interfering with the user requested transformation.

Differential Revision: https://reviews.llvm.org/D114886
  • Loading branch information
syzaara committed Dec 14, 2021
1 parent 423f196 commit dd245ba
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,31 @@ static LoopUnrollResult tryToUnrollLoop(
TransformationMode TM = hasUnrollTransformation(L);
if (TM & TM_Disable)
return LoopUnrollResult::Unmodified;

// If this loop isn't forced to be unrolled, avoid unrolling it when the
// parent loop has an explicit unroll-and-jam pragma. This is to prevent
// automatic unrolling from interfering with the user requested
// transformation.
Loop *ParentL = L->getParentLoop();
if (ParentL != NULL &&
hasUnrollAndJamTransformation(ParentL) == TM_ForcedByUser &&
hasUnrollTransformation(L) != TM_ForcedByUser) {
LLVM_DEBUG(dbgs() << "Not unrolling loop since parent loop has"
<< " llvm.loop.unroll_and_jam.\n");
return LoopUnrollResult::Unmodified;
}

// If this loop isn't forced to be unrolled, avoid unrolling it when the
// loop has an explicit unroll-and-jam pragma. This is to prevent automatic
// unrolling from interfering with the user requested transformation.
if (hasUnrollAndJamTransformation(L) == TM_ForcedByUser &&
hasUnrollTransformation(L) != TM_ForcedByUser) {
LLVM_DEBUG(
dbgs()
<< " Not unrolling loop since it has llvm.loop.unroll_and_jam.\n");
return LoopUnrollResult::Unmodified;
}

if (!L->isLoopSimplifyForm()) {
LLVM_DEBUG(
dbgs() << " Not unrolling loop which is not in loop-simplify form.\n");
Expand Down

0 comments on commit dd245ba

Please sign in to comment.