Skip to content

Commit 7173b66

Browse files
committedMar 21, 2015
[CodeGen][IfCvt] Don't re-ifcvt blocks with unanalyzable terminators.
If we couldn't analyze its terminator (i.e., it's an indirectbr, or some other weirdness), we can't safely re-if-convert a predicated block, because we can't tell whether the predicated terminator can fallthrough (it does). Currently, we would completely ignore the fallthrough successor. In the added testcase, this means we used to generate: ... @ %entry: cmp r5, #21 ittt ne @ %cc1f: cmpne r7, #42 @ %cc2t: strne.w r5, [r8] movne pc, r10 @ %cc1t: ... Whereas the successor of %cc1f was originally %bb1. With the fix, we get the correct: ... @ %entry: cmp r5, #21 itt eq @ %cc1t: streq.w r5, [r11] moveq pc, r0 @ %cc1f: cmp r7, #42 itt ne @ %cc2t: strne.w r5, [r8] movne pc, r10 @ %bb1: ... rdar://20192768 Differential Revision: http://reviews.llvm.org/D8509 llvm-svn: 232872
1 parent e6bb09a commit 7173b66

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
 

Diff for: ‎llvm/lib/CodeGen/IfConversion.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,12 @@ bool IfConverter::FeasibilityAnalysis(BBInfo &BBI,
726726
if (BBI.IsDone || BBI.IsUnpredicable)
727727
return false;
728728

729+
// If it is already predicated but we couldn't analyze its terminator, the
730+
// latter might fallthrough, but we can't determine where to.
731+
// Conservatively avoid if-converting again.
732+
if (BBI.Predicate.size() && !BBI.IsBrAnalyzable)
733+
return false;
734+
729735
// If it is already predicated, check if the new predicate subsumes
730736
// its predicate.
731737
if (BBI.Predicate.size() && !TII->SubsumesPredicate(Pred, BBI.Predicate))

Diff for: ‎llvm/test/CodeGen/ARM/ifcvt-iter-indbr.ll

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
; RUN: llc < %s -mtriple thumbv7s-apple-darwin -asm-verbose=false | FileCheck %s
2+
3+
declare i32 @foo(i32)
4+
declare i8* @bar(i32, i8*, i8*)
5+
6+
; Verify that we don't try to iteratively re-ifconvert a block with a
7+
; (predicated) indirectbr terminator.
8+
; If we do, we would ignore its fallthrough successor.
9+
10+
11+
; CHECK-LABEL: test:
12+
; CHECK: cmp {{.*}}, #21
13+
; CHECK-NEXT: itt eq
14+
; CHECK-NEXT: streq.w
15+
; CHECK-NEXT: moveq pc
16+
; CHECK-NEXT: LBB{{[0-9_]+}}:
17+
; CHECK-NEXT: cmp {{.*}}, #42
18+
; CHECK-NEXT: itt ne
19+
; CHECK-NEXT: strne.w
20+
; CHECK-NEXT: movne pc
21+
; CHECK-NEXT: Ltmp
22+
; CHECK-NEXT: LBB0_2:
23+
; CHECK-NEXT: movw r0, #1234
24+
; CHECK-NEXT: b [[FOOCALL:LBB[0-9_]+]]
25+
; CHECK-NEXT: Ltmp
26+
; CHECK-NEXT: LBB{{[0-9_]+}}:
27+
; CHECK-NEXT: movw r0, #4567
28+
; CHECK-NEXT: [[FOOCALL]]:
29+
; CHECK-NEXT: blx _foo
30+
31+
define i32 @test(i32 %a, i32 %a2, i32* %p, i32* %p2) {
32+
entry:
33+
%dst1 = call i8* @bar(i32 1, i8* blockaddress(@test, %bb1), i8* blockaddress(@test, %bb2))
34+
%dst2 = call i8* @bar(i32 2, i8* blockaddress(@test, %bb1), i8* blockaddress(@test, %bb2))
35+
%dst3 = call i8* @bar(i32 3, i8* blockaddress(@test, %bb1), i8* blockaddress(@test, %bb2))
36+
%cc1 = icmp eq i32 %a, 21
37+
br i1 %cc1, label %cc1t, label %cc1f
38+
39+
cc1t:
40+
store i32 %a, i32* %p
41+
indirectbr i8* %dst3, [label %bb1, label %bb2]
42+
43+
cc1f:
44+
%cc2 = icmp ne i32 %a2, 42
45+
br i1 %cc2, label %cc2t, label %bb1
46+
cc2t:
47+
store i32 %a, i32* %p2
48+
indirectbr i8* %dst1, [label %bb1, label %bb2]
49+
50+
bb1:
51+
%ret_bb1 = call i32 @foo(i32 1234)
52+
ret i32 %ret_bb1
53+
bb2:
54+
%ret_bb2 = call i32 @foo(i32 4567)
55+
ret i32 %ret_bb2
56+
}

0 commit comments

Comments
 (0)
Please sign in to comment.