1 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu -mcpu=pwr9 < %s | FileCheck %s
3 ; If there is an exit edge known to be frequently taken,
4 ; we should not transform this loop.
6 ; A loop having a hot exit edge (exit in false branch)
7 define signext i64 @func() {
13 %a = alloca [1000 x i32], align 4
17 %i.013 = phi i64 [ 0, %entry ], [ %inc, %if.end ]
18 %b.012 = phi i64 [ 0, %entry ], [ %xor, %if.end ]
19 %arrayidx = getelementptr inbounds [1000 x i32], ptr %a, i64 0, i64 %i.013
20 %0 = load i32, ptr %arrayidx, align 4
21 %tobool = icmp eq i32 %0, 0
22 br i1 %tobool, label %if.end, label %cleanup, !prof !1
25 %xor = xor i64 %i.013, %b.012
26 %inc = add nuw nsw i64 %i.013, 1
27 %cmp = icmp ult i64 %inc, 1000
28 br i1 %cmp, label %for.body, label %cleanup
31 %res = phi i64 [ %b.012, %for.body ], [ %xor, %if.end ]
35 ; A loop having a cold exit edge (exit in false branch)
36 define signext i64 @func2() {
42 %a = alloca [1000 x i32], align 4
46 %i.013 = phi i64 [ 0, %entry ], [ %inc, %if.end ]
47 %b.012 = phi i64 [ 0, %entry ], [ %xor, %if.end ]
48 %arrayidx = getelementptr inbounds [1000 x i32], ptr %a, i64 0, i64 %i.013
49 %0 = load i32, ptr %arrayidx, align 4
50 %tobool = icmp eq i32 %0, 0
51 br i1 %tobool, label %if.end, label %cleanup, !prof !2
54 %xor = xor i64 %i.013, %b.012
55 %inc = add nuw nsw i64 %i.013, 1
56 %cmp = icmp ult i64 %inc, 1000
57 br i1 %cmp, label %for.body, label %cleanup
60 %res = phi i64 [ %b.012, %for.body ], [ %xor, %if.end ]
64 ; A loop having an exit edge without profile data (exit in false branch)
65 define signext i64 @func3() {
71 %a = alloca [1000 x i32], align 4
75 %i.013 = phi i64 [ 0, %entry ], [ %inc, %if.end ]
76 %b.012 = phi i64 [ 0, %entry ], [ %xor, %if.end ]
77 %arrayidx = getelementptr inbounds [1000 x i32], ptr %a, i64 0, i64 %i.013
78 %0 = load i32, ptr %arrayidx, align 4
79 %tobool = icmp eq i32 %0, 0
80 br i1 %tobool, label %if.end, label %cleanup
83 %xor = xor i64 %i.013, %b.012
84 %inc = add nuw nsw i64 %i.013, 1
85 %cmp = icmp ult i64 %inc, 1000
86 br i1 %cmp, label %for.body, label %cleanup
89 %res = phi i64 [ %b.012, %for.body ], [ %xor, %if.end ]
93 ; A loop having a hot exit edge (exit in true branch)
94 define signext i64 @func4() {
100 %a = alloca [1000 x i32], align 4
104 %i.013 = phi i64 [ 0, %entry ], [ %inc, %if.end ]
105 %b.012 = phi i64 [ 0, %entry ], [ %xor, %if.end ]
106 %arrayidx = getelementptr inbounds [1000 x i32], ptr %a, i64 0, i64 %i.013
107 %0 = load i32, ptr %arrayidx, align 4
108 %tobool = icmp ne i32 %0, 0
109 br i1 %tobool, label %cleanup, label %if.end, !prof !2
112 %xor = xor i64 %i.013, %b.012
113 %inc = add nuw nsw i64 %i.013, 1
114 %cmp = icmp ult i64 %inc, 1000
115 br i1 %cmp, label %for.body, label %cleanup
118 %res = phi i64 [ %b.012, %for.body ], [ %xor, %if.end ]
122 ; A loop having a cold exit edge (exit in true branch)
123 define signext i64 @func5() {
129 %a = alloca [1000 x i32], align 4
133 %i.013 = phi i64 [ 0, %entry ], [ %inc, %if.end ]
134 %b.012 = phi i64 [ 0, %entry ], [ %xor, %if.end ]
135 %arrayidx = getelementptr inbounds [1000 x i32], ptr %a, i64 0, i64 %i.013
136 %0 = load i32, ptr %arrayidx, align 4
137 %tobool = icmp ne i32 %0, 0
138 br i1 %tobool, label %cleanup, label %if.end, !prof !1
141 %xor = xor i64 %i.013, %b.012
142 %inc = add nuw nsw i64 %i.013, 1
143 %cmp = icmp ult i64 %inc, 1000
144 br i1 %cmp, label %for.body, label %cleanup
147 %res = phi i64 [ %b.012, %for.body ], [ %xor, %if.end ]
151 ; A loop having an exit edge without profile data (exit in true branch)
152 define signext i64 @func6() {
158 %a = alloca [1000 x i32], align 4
162 %i.013 = phi i64 [ 0, %entry ], [ %inc, %if.end ]
163 %b.012 = phi i64 [ 0, %entry ], [ %xor, %if.end ]
164 %arrayidx = getelementptr inbounds [1000 x i32], ptr %a, i64 0, i64 %i.013
165 %0 = load i32, ptr %arrayidx, align 4
166 %tobool = icmp ne i32 %0, 0
167 br i1 %tobool, label %cleanup, label %if.end
170 %xor = xor i64 %i.013, %b.012
171 %inc = add nuw nsw i64 %i.013, 1
172 %cmp = icmp ult i64 %inc, 1000
173 br i1 %cmp, label %for.body, label %cleanup
176 %res = phi i64 [ %b.012, %for.body ], [ %xor, %if.end ]
180 !1 = !{!"branch_weights", i32 1, i32 2000}
181 !2 = !{!"branch_weights", i32 2000, i32 1}