[llvm-branch-commits] [llvm] cf5415c - [PGO][PGSO] Let unroll hints take precedence over PGSO.
Hiroshi Yamauchi via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Jan 7 10:15:22 PST 2021
Author: Hiroshi Yamauchi
Date: 2021-01-07T10:10:31-08:00
New Revision: cf5415c727dda0ea4b27ee16347d170f118b037b
URL: https://github.com/llvm/llvm-project/commit/cf5415c727dda0ea4b27ee16347d170f118b037b
DIFF: https://github.com/llvm/llvm-project/commit/cf5415c727dda0ea4b27ee16347d170f118b037b.diff
LOG: [PGO][PGSO] Let unroll hints take precedence over PGSO.
Differential Revision: https://reviews.llvm.org/D94199
Added:
Modified:
llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
llvm/test/Transforms/LoopUnroll/unroll-opt-attribute.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
index 4cce05d595a8..d09f1ee22a75 100644
--- a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
@@ -218,8 +218,10 @@ TargetTransformInfo::UnrollingPreferences llvm::gatherUnrollingPreferences(
// Apply size attributes
bool OptForSize = L->getHeader()->getParent()->hasOptSize() ||
- llvm::shouldOptimizeForSize(L->getHeader(), PSI, BFI,
- PGSOQueryType::IRPass);
+ // Let unroll hints / pragmas take precedence over PGSO.
+ (hasUnrollTransformation(L) != TM_ForcedByUser &&
+ llvm::shouldOptimizeForSize(L->getHeader(), PSI, BFI,
+ PGSOQueryType::IRPass));
if (OptForSize) {
UP.Threshold = UP.OptSizeThreshold;
UP.PartialThreshold = UP.PartialOptSizeThreshold;
diff --git a/llvm/test/Transforms/LoopUnroll/unroll-opt-attribute.ll b/llvm/test/Transforms/LoopUnroll/unroll-opt-attribute.ll
index e219349fb093..884981bf8bf0 100644
--- a/llvm/test/Transforms/LoopUnroll/unroll-opt-attribute.ll
+++ b/llvm/test/Transforms/LoopUnroll/unroll-opt-attribute.ll
@@ -158,6 +158,38 @@ for.end: ; preds = %for.body
; NPGSO-NOT: phi
; NPGSO-NOT: icmp
+;///////////////////// TEST 6 //////////////////////////////
+
+; This test tests that unroll hints take precedence over PGSO and that this loop
+; gets unrolled even though it's cold.
+
+define i32 @Test6() !prof !14 {
+entry:
+ br label %for.body
+
+for.body: ; preds = %for.body, %entry
+ %i.05 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
+ %arrayidx = getelementptr inbounds [24 x i32], [24 x i32]* @tab, i32 0, i32 %i.05
+ store i32 %i.05, i32* %arrayidx, align 4
+ %inc = add nuw nsw i32 %i.05, 1
+ %exitcond = icmp eq i32 %inc, 24
+ br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !15
+
+for.end: ; preds = %for.body
+ ret i32 42
+}
+
+; PGSO-LABEL: @Test6
+; PGSO: store
+; PGSO: store
+; PGSO: store
+; PGSO: store
+; NPGSO-LABEL: @Test6
+; NPGSO: store
+; NPGSO: store
+; NPGSO: store
+; NPGSO: store
+
!llvm.module.flags = !{!0}
!0 = !{i32 1, !"ProfileSummary", !1}
!1 = !{!2, !3, !4, !5, !6, !7, !8, !9}
@@ -174,3 +206,5 @@ for.end: ; preds = %for.body
!12 = !{i32 999000, i64 100, i32 1}
!13 = !{i32 999999, i64 1, i32 2}
!14 = !{!"function_entry_count", i64 0}
+!15 = !{!15, !16}
+!16 = !{!"llvm.loop.unroll.count", i32 4}
More information about the llvm-branch-commits
mailing list