]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/Transforms/SimplifyCFG/branch-fold-threshold.ll
Vendor import of llvm trunk r351319 (just before the release_80 branch
[FreeBSD/FreeBSD.git] / test / Transforms / SimplifyCFG / branch-fold-threshold.ll
1 ; RUN: opt %s -simplifycfg -S | FileCheck %s --check-prefix=NORMAL
2 ; RUN: opt %s -simplifycfg -S -bonus-inst-threshold=2 | FileCheck %s --check-prefix=AGGRESSIVE
3 ; RUN: opt %s -simplifycfg -S -bonus-inst-threshold=4 | FileCheck %s --check-prefix=WAYAGGRESSIVE
4
5 define i32 @foo(i32 %a, i32 %b, i32 %c, i32 %d, i32* %input) {
6 ; NORMAL-LABEL: @foo(
7 ; AGGRESSIVE-LABEL: @foo(
8 entry:
9   %cmp = icmp sgt i32 %d, 3
10   br i1 %cmp, label %cond.end, label %lor.lhs.false
11 ; NORMAL: br i1
12 ; AGGRESSIVE: br i1
13
14 lor.lhs.false:
15   %mul = shl i32 %c, 1
16   %add = add nsw i32 %mul, %a
17   %cmp1 = icmp slt i32 %add, %b
18   br i1 %cmp1, label %cond.false, label %cond.end
19 ; NORMAL: br i1
20 ; AGGRESSIVE-NOT: br i1
21
22 cond.false:
23   %0 = load i32, i32* %input, align 4
24   br label %cond.end
25
26 cond.end:
27   %cond = phi i32 [ %0, %cond.false ], [ 0, %lor.lhs.false ], [ 0, %entry ]
28   ret i32 %cond
29 }
30
31 declare void @distinct_a();
32 declare void @distinct_b();
33
34 ;; Like foo, but have to duplicate into multiple predecessors
35 define i32 @bar(i32 %a, i32 %b, i32 %c, i32 %d, i32* %input) {
36 ; NORMAL-LABEL: @bar(
37 ; AGGRESSIVE-LABEL: @bar(
38 entry:
39   %cmp_split = icmp slt i32 %d, %b
40   %cmp = icmp sgt i32 %d, 3
41   br i1 %cmp_split, label %pred_a, label %pred_b
42 pred_a:
43 ; NORMAL-LABEL: pred_a:
44 ; AGGRESSIVE-LABEL: pred_a:
45 ; WAYAGGRESSIVE-LABEL: pred_a:
46 ; NORMAL: br i1
47 ; AGGRESSIVE: br i1
48 ; WAYAGGRESSIVE: br i1
49   call void @distinct_a();
50   br i1 %cmp, label %cond.end, label %lor.lhs.false
51 pred_b:
52 ; NORMAL-LABEL: pred_b:
53 ; AGGRESSIVE-LABEL: pred_b:
54 ; WAYAGGRESSIVE-LABEL: pred_b:
55 ; NORMAL: br i1
56 ; AGGRESSIVE: br i1
57 ; WAYAGGRESSIVE: br i1
58   call void @distinct_b();
59   br i1 %cmp, label %cond.end, label %lor.lhs.false
60
61 lor.lhs.false:
62   %mul = shl i32 %c, 1
63   %add = add nsw i32 %mul, %a
64   %cmp1 = icmp slt i32 %add, %b
65   br i1 %cmp1, label %cond.false, label %cond.end
66 ; NORMAL-LABEL: lor.lhs.false:
67 ; AGGRESIVE-LABEL: lor.lhs.false:
68 ; WAYAGGRESIVE-LABEL: lor.lhs.false:
69 ; NORMAL: br i1
70 ; AGGRESSIVE: br i1
71 ; WAYAGGRESSIVE-NOT: br i1
72
73 cond.false:
74   %0 = load i32, i32* %input, align 4
75   br label %cond.end
76
77 cond.end:
78   %cond = phi i32 [ %0, %cond.false ], [ 0, %lor.lhs.false ],[ 0, %pred_a ],[ 0, %pred_b ]
79   ret i32 %cond
80 }