Skip to content

Commit 0eda454

Browse files
committed
[SimpleLoopUnswitch] Don't non-trivially unswitch loops that are unsafe to clone
Non-trivial unswitching can clone loops. The legacy -loop-unswitch pass also checks for this. Fixes PR49085. Reviewed By: asbirlea Differential Revision: https://reviews.llvm.org/D96288
1 parent 69f5bd2 commit 0eda454

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2910,6 +2910,10 @@ static bool unswitchLoop(Loop &L, DominatorTree &DT, LoopInfo &LI,
29102910
if (L.getHeader()->getParent()->hasOptSize())
29112911
return false;
29122912

2913+
// Skip non-trivial unswitching for loops that cannot be cloned.
2914+
if (!L.isSafeToClone())
2915+
return false;
2916+
29132917
// For non-trivial unswitching, because it often creates new loops, we rely on
29142918
// the pass manager to iterate on the loops rather than trying to immediately
29152919
// reach a fixed point. There is no substantial advantage to iterating
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
; RUN: opt -passes='unswitch<nontrivial>' %s -S | FileCheck %s
2+
3+
declare i1 @foo()
4+
5+
; CHECK: define {{.*}} @mem_cgroup_node_nr_lru_pages
6+
define i32 @mem_cgroup_node_nr_lru_pages(i1 %tree) {
7+
entry:
8+
br label %for.cond
9+
10+
for.cond: ; preds = %if.end8, %entry
11+
br i1 %tree, label %if.end8, label %if.else
12+
13+
if.else: ; preds = %for.cond
14+
callbr void asm sideeffect ".pushsection __jump_table, \22aw\22 \0A\09.popsection \0A\09", "X,~{dirflag},~{fpsr},~{flags}"(i8* blockaddress(@mem_cgroup_node_nr_lru_pages, %for.cond5))
15+
to label %if.end8 [label %for.cond5]
16+
17+
for.cond5: ; preds = %if.else, %for.cond5
18+
%call6 = call i1 @foo()
19+
br i1 %call6, label %if.end8.loopexit, label %for.cond5
20+
21+
if.end8.loopexit: ; preds = %for.cond5
22+
br label %if.end8
23+
24+
if.end8: ; preds = %if.end8.loopexit, %if.else, %for.cond
25+
br label %for.cond
26+
}
27+

0 commit comments

Comments
 (0)