Skip to content

[LoopRotation] Allow loop header duplication if vectorization is forced. #2046

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions llvm/lib/Transforms/Scalar/LoopRotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ LoopRotatePass::LoopRotatePass(bool EnableHeaderDuplication)
PreservedAnalyses LoopRotatePass::run(Loop &L, LoopAnalysisManager &AM,
LoopStandardAnalysisResults &AR,
LPMUpdater &) {
int Threshold = EnableHeaderDuplication ? DefaultRotationThreshold : 0;
// Vectorization requires loop-rotation. Use default threshold for loops the
// user explicitly marked for vectorization, even when header duplication is
// disabled.
int Threshold = EnableHeaderDuplication ||
hasVectorizeTransformation(&L) == TM_ForcedByUser
? DefaultRotationThreshold
: 0;
const DataLayout &DL = L.getHeader()->getModule()->getDataLayout();
const SimplifyQuery SQ = getBestSimplifyQuery(AR, DL);

Expand Down Expand Up @@ -105,9 +111,16 @@ class LoopRotateLegacyPass : public LoopPass {
if (MSSAA)
MSSAU = MemorySSAUpdater(&MSSAA->getMSSA());
}
// Vectorization requires loop-rotation. Use default threshold for loops the
// user explicitly marked for vectorization, even when header duplication is
// disabled.
int Threshold = hasVectorizeTransformation(L) == TM_ForcedByUser
? DefaultRotationThreshold
: MaxHeaderSize;

return LoopRotation(L, LI, TTI, AC, &DT, &SE,
MSSAU.hasValue() ? MSSAU.getPointer() : nullptr, SQ,
false, MaxHeaderSize, false);
false, Threshold, false);
}
};
} // end namespace
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
; RUN: opt -Oz -S -enable-new-pm=0 < %s | FileCheck %s
; RUN: opt -passes='default<Oz>' -S < %s | FileCheck %s

; Forcing vectorization should allow for more aggressive loop-rotation with
; -Oz, because LV requires rotated loops. Make sure the loop in @foo is
; vectorized with -Oz.

target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
target triple = "arm64-apple-ios5.0.0"

define void @foo(float* noalias nocapture %ptrA, float* noalias nocapture readonly %ptrB, i64 %size) {
; CHECK-LABEL: @foo(
; CHECK: fmul <4 x float>
;
entry:
br label %for.cond

for.cond: ; preds = %for.body, %entry
%indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]
%exitcond = icmp eq i64 %indvars.iv, %size
br i1 %exitcond, label %for.cond.cleanup, label %for.body

for.body: ; preds = %for.cond
%arrayidx = getelementptr inbounds float, float* %ptrB, i64 %indvars.iv
%0 = load float, float* %arrayidx, align 4
%arrayidx2 = getelementptr inbounds float, float* %ptrA, i64 %indvars.iv
%1 = load float, float* %arrayidx2, align 4
%mul3 = fmul float %0, %1
store float %mul3, float* %arrayidx2, align 4
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
br label %for.cond, !llvm.loop !0

for.cond.cleanup: ; preds = %for.cond
ret void
}

!0 = distinct !{!0, !1}
!1 = !{!"llvm.loop.vectorize.enable", i1 true}