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
14 %0 = bitcast [1000 x i32]* %a to i8*
18 %i.013 = phi i64 [ 0, %entry ], [ %inc, %if.end ]
19 %b.012 = phi i64 [ 0, %entry ], [ %xor, %if.end ]
20 %arrayidx = getelementptr inbounds [1000 x i32], [1000 x i32]* %a, i64 0, i64 %i.013
21 %1 = load i32, i32* %arrayidx, align 4
22 %tobool = icmp eq i32 %1, 0
23 br i1 %tobool, label %if.end, label %cleanup, !prof !1
26 %xor = xor i64 %i.013, %b.012
27 %inc = add nuw nsw i64 %i.013, 1
28 %cmp = icmp ult i64 %inc, 1000
29 br i1 %cmp, label %for.body, label %cleanup
32 %res = phi i64 [ %b.012, %for.body ], [ %xor, %if.end ]
36 ; A loop having a cold exit edge (exit in false branch)
37 define signext i64 @func2() {
43 %a = alloca [1000 x i32], align 4
44 %0 = bitcast [1000 x i32]* %a to i8*
48 %i.013 = phi i64 [ 0, %entry ], [ %inc, %if.end ]
49 %b.012 = phi i64 [ 0, %entry ], [ %xor, %if.end ]
50 %arrayidx = getelementptr inbounds [1000 x i32], [1000 x i32]* %a, i64 0, i64 %i.013
51 %1 = load i32, i32* %arrayidx, align 4
52 %tobool = icmp eq i32 %1, 0
53 br i1 %tobool, label %if.end, label %cleanup, !prof !2
56 %xor = xor i64 %i.013, %b.012
57 %inc = add nuw nsw i64 %i.013, 1
58 %cmp = icmp ult i64 %inc, 1000
59 br i1 %cmp, label %for.body, label %cleanup
62 %res = phi i64 [ %b.012, %for.body ], [ %xor, %if.end ]
66 ; A loop having an exit edge without profile data (exit in false branch)
67 define signext i64 @func3() {
73 %a = alloca [1000 x i32], align 4
74 %0 = bitcast [1000 x i32]* %a to i8*
78 %i.013 = phi i64 [ 0, %entry ], [ %inc, %if.end ]
79 %b.012 = phi i64 [ 0, %entry ], [ %xor, %if.end ]
80 %arrayidx = getelementptr inbounds [1000 x i32], [1000 x i32]* %a, i64 0, i64 %i.013
81 %1 = load i32, i32* %arrayidx, align 4
82 %tobool = icmp eq i32 %1, 0
83 br i1 %tobool, label %if.end, label %cleanup
86 %xor = xor i64 %i.013, %b.012
87 %inc = add nuw nsw i64 %i.013, 1
88 %cmp = icmp ult i64 %inc, 1000
89 br i1 %cmp, label %for.body, label %cleanup
92 %res = phi i64 [ %b.012, %for.body ], [ %xor, %if.end ]
96 ; A loop having a hot exit edge (exit in true branch)
97 define signext i64 @func4() {
103 %a = alloca [1000 x i32], align 4
104 %0 = bitcast [1000 x i32]* %a to i8*
108 %i.013 = phi i64 [ 0, %entry ], [ %inc, %if.end ]
109 %b.012 = phi i64 [ 0, %entry ], [ %xor, %if.end ]
110 %arrayidx = getelementptr inbounds [1000 x i32], [1000 x i32]* %a, i64 0, i64 %i.013
111 %1 = load i32, i32* %arrayidx, align 4
112 %tobool = icmp ne i32 %1, 0
113 br i1 %tobool, label %cleanup, label %if.end, !prof !2
116 %xor = xor i64 %i.013, %b.012
117 %inc = add nuw nsw i64 %i.013, 1
118 %cmp = icmp ult i64 %inc, 1000
119 br i1 %cmp, label %for.body, label %cleanup
122 %res = phi i64 [ %b.012, %for.body ], [ %xor, %if.end ]
126 ; A loop having a cold exit edge (exit in true branch)
127 define signext i64 @func5() {
133 %a = alloca [1000 x i32], align 4
134 %0 = bitcast [1000 x i32]* %a to i8*
138 %i.013 = phi i64 [ 0, %entry ], [ %inc, %if.end ]
139 %b.012 = phi i64 [ 0, %entry ], [ %xor, %if.end ]
140 %arrayidx = getelementptr inbounds [1000 x i32], [1000 x i32]* %a, i64 0, i64 %i.013
141 %1 = load i32, i32* %arrayidx, align 4
142 %tobool = icmp ne i32 %1, 0
143 br i1 %tobool, label %cleanup, label %if.end, !prof !1
146 %xor = xor i64 %i.013, %b.012
147 %inc = add nuw nsw i64 %i.013, 1
148 %cmp = icmp ult i64 %inc, 1000
149 br i1 %cmp, label %for.body, label %cleanup
152 %res = phi i64 [ %b.012, %for.body ], [ %xor, %if.end ]
156 ; A loop having an exit edge without profile data (exit in true branch)
157 define signext i64 @func6() {
163 %a = alloca [1000 x i32], align 4
164 %0 = bitcast [1000 x i32]* %a to i8*
168 %i.013 = phi i64 [ 0, %entry ], [ %inc, %if.end ]
169 %b.012 = phi i64 [ 0, %entry ], [ %xor, %if.end ]
170 %arrayidx = getelementptr inbounds [1000 x i32], [1000 x i32]* %a, i64 0, i64 %i.013
171 %1 = load i32, i32* %arrayidx, align 4
172 %tobool = icmp ne i32 %1, 0
173 br i1 %tobool, label %cleanup, label %if.end
176 %xor = xor i64 %i.013, %b.012
177 %inc = add nuw nsw i64 %i.013, 1
178 %cmp = icmp ult i64 %inc, 1000
179 br i1 %cmp, label %for.body, label %cleanup
182 %res = phi i64 [ %b.012, %for.body ], [ %xor, %if.end ]
186 !1 = !{!"branch_weights", i32 1, i32 2000}
187 !2 = !{!"branch_weights", i32 2000, i32 1}