Skip to content

Commit 9e95011

Browse files
aykevlyuxuanchen1997
authored andcommitted
[LoopRotate] Don't rotate loops when the minsize attribute is present
Summary: The main use for this patch is LTO. It is not (yet?) possible to set the size level (-Os, -Oz) in the linker, which means loops are still rotated even if -Oz is specified on the command line. Therefore, look at the function attribute instead of only at the size level to determine whether to rotate loops for a given function. For discussion, see: https://reviews.llvm.org/D119342 An older version of this patch was already approved at https://reviews.llvm.org/D119342 but I never got around to committing it. The code changed so I had to make some minor updates to this patch and in the meantime I also lost commit access because I wasn't really using it. So here is an updated patch. Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251749
1 parent a39c19b commit 9e95011

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

llvm/lib/Transforms/Scalar/LoopRotation.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,11 @@ PreservedAnalyses LoopRotatePass::run(Loop &L, LoopAnalysisManager &AM,
6464
// Vectorization requires loop-rotation. Use default threshold for loops the
6565
// user explicitly marked for vectorization, even when header duplication is
6666
// disabled.
67-
int Threshold = EnableHeaderDuplication ||
68-
hasVectorizeTransformation(&L) == TM_ForcedByUser
69-
? DefaultRotationThreshold
70-
: 0;
67+
int Threshold =
68+
(EnableHeaderDuplication && !L.getHeader()->getParent()->hasMinSize()) ||
69+
hasVectorizeTransformation(&L) == TM_ForcedByUser
70+
? DefaultRotationThreshold
71+
: 0;
7172
const DataLayout &DL = L.getHeader()->getDataLayout();
7273
const SimplifyQuery SQ = getBestSimplifyQuery(AR, DL);
7374

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
; REQUIRES: asserts
2+
; RUN: opt < %s -S -passes=loop-rotate -debug -debug-only=loop-rotate 2>&1 | FileCheck %s
3+
4+
; Loop should not be rotated for functions with the minsize attribute.
5+
; This is mostly useful for LTO which doesn't (yet) understand -Oz.
6+
; CHECK: LoopRotation: NOT rotating - contains 2 instructions, which is more
7+
8+
@e = global i32 10
9+
10+
declare void @use(i32)
11+
12+
; Function attrs: minsize optsize
13+
define void @test() #0 {
14+
entry:
15+
%end = load i32, ptr @e
16+
br label %loop
17+
18+
loop:
19+
%n.phi = phi i32 [ %n, %loop.fin ], [ 0, %entry ]
20+
%cond = icmp eq i32 %n.phi, %end
21+
br i1 %cond, label %exit, label %loop.fin
22+
23+
loop.fin:
24+
%n = add i32 %n.phi, 1
25+
call void @use(i32 %n)
26+
br label %loop
27+
28+
exit:
29+
ret void
30+
}
31+
32+
attributes #0 = { minsize optsize }

0 commit comments

Comments
 (0)