Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit ff78b27

Browse files
authored
Merge pull request #115 from nikic/simplifycfg-latch
Backport fix for encoding_rs performance regression
2 parents 1abfd0e + 823320b commit ff78b27

File tree

5 files changed

+29
-13
lines changed

5 files changed

+29
-13
lines changed

lib/Transforms/Utils/SimplifyCFG.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -5721,9 +5721,12 @@ bool SimplifyCFGOpt::SimplifyUncondBranch(BranchInst *BI,
57215721
// header. (This is for early invocations before loop simplify and
57225722
// vectorization to keep canonical loop forms for nested loops. These blocks
57235723
// can be eliminated when the pass is invoked later in the back-end.)
5724+
// Note that if BB has only one predecessor then we do not introduce new
5725+
// backedge, so we can eliminate BB.
57245726
bool NeedCanonicalLoop =
57255727
Options.NeedCanonicalLoop &&
5726-
(LoopHeaders && (LoopHeaders->count(BB) || LoopHeaders->count(Succ)));
5728+
(LoopHeaders && std::distance(pred_begin(BB), pred_end(BB)) > 1 &&
5729+
(LoopHeaders->count(BB) || LoopHeaders->count(Succ)));
57275730
BasicBlock::iterator I = BB->getFirstNonPHIOrDbg()->getIterator();
57285731
if (I->isTerminator() && BB != &BB->getParent()->getEntryBlock() &&
57295732
!NeedCanonicalLoop && TryToSimplifyUncondBranchFromEmptyBlock(BB))

test/Transforms/LoopUnroll/peel-loop.ll

+4-9
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@
1919
; CHECK: store i32 2, i32* %[[INC2]], align 4
2020
; CHECK: %[[CMP3:.*]] = icmp eq i32 %k, 3
2121
; CHECK: br i1 %[[CMP3]], label %for.end, label %[[LOOP_PH:.*]]
22-
; CHECK: [[LOOP_PH]]:
23-
; CHECK: br label %[[LOOP:.*]]
24-
; CHECK: [[LOOP]]:
25-
; CHECK: %[[IV:.*]] = phi i32 [ 3, %[[LOOP_PH]] ], [ {{.*}}, %[[LOOP]] ]
22+
; CHECK: for.end:
23+
; CHECK: ret void
2624

2725
define void @basic(i32* %p, i32 %k) #0 {
2826
entry:
@@ -68,11 +66,8 @@ for.end: ; preds = %for.cond.for.end_cr
6866
; CHECK: store i32 2, i32* %[[INC2]], align 4
6967
; CHECK: %[[CMP3:.*]] = icmp eq i32 %k, 3
7068
; CHECK: br i1 %[[CMP3]], label %for.end, label %[[LOOP_PH:.*]]
71-
; CHECK: [[LOOP_PH]]:
72-
; CHECK: br label %[[LOOP:.*]]
73-
; CHECK: [[LOOP]]:
74-
; CHECK: %[[IV:.*]] = phi i32 [ 3, %[[LOOP_PH]] ], [ %[[IV:.*]], %[[LOOP]] ]
75-
; CHECK: %ret = phi i32 [ 0, %entry ], [ 1, %[[NEXT0]] ], [ 2, %[[NEXT1]] ], [ 3, %[[NEXT2]] ], [ %[[IV]], %[[LOOP]] ]
69+
; CHECK: for.end:
70+
; CHECK: %ret = phi i32 [ 0, %entry ], [ 1, %[[NEXT0]] ], [ 2, %[[NEXT1]] ], [ 3, %[[NEXT2]] ], [ %inc, %for.body ]
7671
; CHECK: ret i32 %ret
7772
define i32 @output(i32* %p, i32 %k) #0 {
7873
entry:

test/Transforms/LoopUnswitch/2015-06-17-Metadata.ll

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ for.body: ; preds = %for.inc, %for.body.
1616
%cmp1 = icmp eq i32 %a, 12345
1717
br i1 %cmp1, label %if.then, label %if.else, !prof !0
1818
; CHECK: %cmp1 = icmp eq i32 %a, 12345
19-
; CHECK-NEXT: br i1 %cmp1, label %for.body.preheader.split.us, label %for.body.preheader.split, !prof !0
19+
; CHECK-NEXT: br i1 %cmp1, label %for.body.us, label %for.body, !prof !0
2020
if.then: ; preds = %for.body
2121
; CHECK: for.body.us:
2222
; CHECK: add nsw i32 %{{.*}}, 123
@@ -53,7 +53,7 @@ entry:
5353
br label %for.body
5454
;CHECK: entry:
5555
;CHECK-NEXT: %cmp1 = icmp eq i32 1, 2
56-
;CHECK-NEXT: br i1 %cmp1, label %entry.split, label %for.cond.cleanup.split, !prof !1
56+
;CHECK-NEXT: br i1 %cmp1, label %for.body, label %for.cond.cleanup.split, !prof !1
5757
;CHECK: for.body:
5858
for.body: ; preds = %for.inc, %entry
5959
%inc.i = phi i32 [ 0, %entry ], [ %inc, %if.then ]

test/Transforms/LoopUnswitch/infinite-loop.ll

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
; CHECK-NEXT: br i1 %a, label %entry.split, label %abort0.split
1717

1818
; CHECK: entry.split:
19-
; CHECK-NEXT: br i1 %b, label %entry.split.split, label %abort1.split
19+
; CHECK-NEXT: br i1 %b, label %for.body, label %abort1.split
2020

2121
; CHECK: for.body:
2222
; CHECK-NEXT: br label %for.body
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; RUN: opt < %s -simplifycfg -S | FileCheck %s
2+
3+
; Check that we can get rid of empty block leading to header
4+
; if it does not introduce new edge.
5+
define i32 @test(i32 %c) {
6+
entry:
7+
br label %header
8+
header:
9+
%i = phi i32 [0, %entry], [%i.1, %backedge]
10+
%i.1 = add i32 %i, 1
11+
%cmp = icmp slt i32 %i.1, %c
12+
br i1 %cmp, label %backedge, label %exit
13+
; CHECK-NOT: backedge:
14+
backedge:
15+
br label %header
16+
exit:
17+
ret i32 %i
18+
}

0 commit comments

Comments
 (0)