[llvm] 8e0c5f7 - [LV] Mark first-order recurrences as allowed exits
Ayal Zaks via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 18 14:00:43 PDT 2020
Author: Ayal Zaks
Date: 2020-04-18T23:54:21+03:00
New Revision: 8e0c5f72005855377197d0f8eb851d7cb889c834
URL: https://github.com/llvm/llvm-project/commit/8e0c5f72005855377197d0f8eb851d7cb889c834
DIFF: https://github.com/llvm/llvm-project/commit/8e0c5f72005855377197d0f8eb851d7cb889c834.diff
LOG: [LV] Mark first-order recurrences as allowed exits
First-order recurrences require special treatment when they are live-out;
such treatment is provided by fixFirstOrderRecurrence(), so they should be
included in AllowedExit set.
(Should probably have been included originally in D16197.)
Fixes PR45526: AllowedExit set is used by prepareToFoldTailByMasking() to
check whether the treatment for live-outs also holds when folding the tail,
which is not (yet) the case for first-order recurrences.
Differential Revision: https://reviews.llvm.org/D78210
Added:
Modified:
llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
llvm/test/Transforms/LoopVectorize/optsize.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
index 0eefa78915b3..f1723cfd1d3f 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
@@ -668,6 +668,7 @@ bool LoopVectorizationLegality::canVectorizeInstrs() {
if (RecurrenceDescriptor::isFirstOrderRecurrence(Phi, TheLoop,
SinkAfter, DT)) {
+ AllowedExit.insert(Phi);
FirstOrderRecurrences.insert(Phi);
continue;
}
diff --git a/llvm/test/Transforms/LoopVectorize/optsize.ll b/llvm/test/Transforms/LoopVectorize/optsize.ll
index 1991906494e4..f0ca35b411c5 100644
--- a/llvm/test/Transforms/LoopVectorize/optsize.ll
+++ b/llvm/test/Transforms/LoopVectorize/optsize.ll
@@ -121,6 +121,39 @@ for.body29:
br i1 %cmp26, label %for.body29, label %for.cond.cleanup28
}
+; PR45526: don't vectorize with fold-tail if first-order-recurrence is live-out.
+;
+define i32 @pr45526() optsize {
+;
+; CHECK-LABEL: @pr45526
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label %loop
+; CHECK-EMPTY:
+; CHECK-NEXT: loop:
+; CHECK-NEXT: %piv = phi i32 [ 0, %entry ], [ %pivPlus1, %loop ]
+; CHECK-NEXT: %for = phi i32 [ 5, %entry ], [ %pivPlus1, %loop ]
+; CHECK-NEXT: %pivPlus1 = add nuw nsw i32 %piv, 1
+; CHECK-NEXT: %cond = icmp ult i32 %piv, 510
+; CHECK-NEXT: br i1 %cond, label %loop, label %exit
+; CHECK-EMPTY:
+; CHECK-NEXT: exit:
+; CHECK-NEXT: %for.lcssa = phi i32 [ %for, %loop ]
+; CHECK-NEXT: ret i32 %for.lcssa
+;
+entry:
+ br label %loop
+
+loop:
+ %piv = phi i32 [ 0, %entry ], [ %pivPlus1, %loop ]
+ %for = phi i32 [ 5, %entry ], [ %pivPlus1, %loop ]
+ %pivPlus1 = add nuw nsw i32 %piv, 1
+ %cond = icmp ult i32 %piv, 510
+ br i1 %cond, label %loop, label %exit
+
+exit:
+ ret i32 %for
+}
+
!llvm.module.flags = !{!0}
!0 = !{i32 1, !"ProfileSummary", !1}
!1 = !{!2, !3, !4, !5, !6, !7, !8, !9}
More information about the llvm-commits
mailing list