182 lines · plain
1; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu -mcpu=pwr9 < %s | FileCheck %s2 3; If there is an exit edge known to be frequently taken,4; we should not transform this loop.5 6; A loop having a hot exit edge (exit in false branch)7define signext i64 @func() {8; CHECK: @func9; CHECK-NOT: mtctr10; CHECK-NOT: bdnz11 12entry:13 %a = alloca [1000 x i32], align 414 br label %for.body15 16for.body: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.01320 %0 = load i32, ptr %arrayidx, align 421 %tobool = icmp eq i32 %0, 022 br i1 %tobool, label %if.end, label %cleanup, !prof !123 24if.end:25 %xor = xor i64 %i.013, %b.01226 %inc = add nuw nsw i64 %i.013, 127 %cmp = icmp ult i64 %inc, 100028 br i1 %cmp, label %for.body, label %cleanup29 30cleanup:31 %res = phi i64 [ %b.012, %for.body ], [ %xor, %if.end ]32 ret i64 %res33}34 35; A loop having a cold exit edge (exit in false branch)36define signext i64 @func2() {37; CHECK: @func238; CHECK: mtctr39; CHECK: bdnz40 41entry:42 %a = alloca [1000 x i32], align 443 br label %for.body44 45for.body: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.01349 %0 = load i32, ptr %arrayidx, align 450 %tobool = icmp eq i32 %0, 051 br i1 %tobool, label %if.end, label %cleanup, !prof !252 53if.end:54 %xor = xor i64 %i.013, %b.01255 %inc = add nuw nsw i64 %i.013, 156 %cmp = icmp ult i64 %inc, 100057 br i1 %cmp, label %for.body, label %cleanup58 59cleanup:60 %res = phi i64 [ %b.012, %for.body ], [ %xor, %if.end ]61 ret i64 %res62}63 64; A loop having an exit edge without profile data (exit in false branch)65define signext i64 @func3() {66; CHECK: @func367; CHECK: mtctr68; CHECK: bdnz69 70entry:71 %a = alloca [1000 x i32], align 472 br label %for.body73 74for.body: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.01378 %0 = load i32, ptr %arrayidx, align 479 %tobool = icmp eq i32 %0, 080 br i1 %tobool, label %if.end, label %cleanup81 82if.end:83 %xor = xor i64 %i.013, %b.01284 %inc = add nuw nsw i64 %i.013, 185 %cmp = icmp ult i64 %inc, 100086 br i1 %cmp, label %for.body, label %cleanup87 88cleanup:89 %res = phi i64 [ %b.012, %for.body ], [ %xor, %if.end ]90 ret i64 %res91}92 93; A loop having a hot exit edge (exit in true branch)94define signext i64 @func4() {95; CHECK: @func496; CHECK-NOT: mtctr97; CHECK-NOT: bdnz98 99entry:100 %a = alloca [1000 x i32], align 4101 br label %for.body102 103for.body: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.013107 %0 = load i32, ptr %arrayidx, align 4108 %tobool = icmp ne i32 %0, 0109 br i1 %tobool, label %cleanup, label %if.end, !prof !2110 111if.end:112 %xor = xor i64 %i.013, %b.012113 %inc = add nuw nsw i64 %i.013, 1114 %cmp = icmp ult i64 %inc, 1000115 br i1 %cmp, label %for.body, label %cleanup116 117cleanup:118 %res = phi i64 [ %b.012, %for.body ], [ %xor, %if.end ]119 ret i64 %res120}121 122; A loop having a cold exit edge (exit in true branch)123define signext i64 @func5() {124; CHECK: @func5125; CHECK: mtctr126; CHECK: bdnz127 128entry:129 %a = alloca [1000 x i32], align 4130 br label %for.body131 132for.body: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.013136 %0 = load i32, ptr %arrayidx, align 4137 %tobool = icmp ne i32 %0, 0138 br i1 %tobool, label %cleanup, label %if.end, !prof !1139 140if.end:141 %xor = xor i64 %i.013, %b.012142 %inc = add nuw nsw i64 %i.013, 1143 %cmp = icmp ult i64 %inc, 1000144 br i1 %cmp, label %for.body, label %cleanup145 146cleanup:147 %res = phi i64 [ %b.012, %for.body ], [ %xor, %if.end ]148 ret i64 %res149}150 151; A loop having an exit edge without profile data (exit in true branch)152define signext i64 @func6() {153; CHECK: @func6154; CHECK: mtctr155; CHECK: bdnz156 157entry:158 %a = alloca [1000 x i32], align 4159 br label %for.body160 161for.body: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.013165 %0 = load i32, ptr %arrayidx, align 4166 %tobool = icmp ne i32 %0, 0167 br i1 %tobool, label %cleanup, label %if.end168 169if.end:170 %xor = xor i64 %i.013, %b.012171 %inc = add nuw nsw i64 %i.013, 1172 %cmp = icmp ult i64 %inc, 1000173 br i1 %cmp, label %for.body, label %cleanup174 175cleanup:176 %res = phi i64 [ %b.012, %for.body ], [ %xor, %if.end ]177 ret i64 %res178}179 180!1 = !{!"branch_weights", i32 1, i32 2000}181!2 = !{!"branch_weights", i32 2000, i32 1}182