brintos

brintos / llvm-project-archived public Read only

0
0
Text · 7.6 KiB · ab88c70 Raw
223 lines · plain
1; This test verifies that the loop vectorizer will not vectorizes low trip count2; loops that require runtime checks (Trip count is computed with profile info).3; REQUIRES: asserts4; RUN: opt < %s -passes=loop-vectorize -loop-vectorize-with-block-frequency -S | FileCheck %s5 6target datalayout = "E-m:e-p:32:32-i64:32-f64:32:64-a:0:32-n32-S128"7 8@tab = common global [32 x i8] zeroinitializer, align 19 10define i32 @foo_low_trip_count1(i32 %bound) {11; Simple loop with low tripcount. Should not be vectorized.12 13; CHECK-LABEL: @foo_low_trip_count1(14; CHECK-NOT: <{{[0-9]+}} x i8>15 16entry:17  br label %for.body18 19for.body:                                         ; preds = %for.body, %entry20  %i.08 = phi i32 [ 0, %entry ], [ %inc, %for.body ]21  %arrayidx = getelementptr inbounds [32 x i8], ptr @tab, i32 0, i32 %i.0822  %0 = load i8, ptr %arrayidx, align 123  %cmp1 = icmp eq i8 %0, 024  %. = select i1 %cmp1, i8 2, i8 125  store i8 %., ptr %arrayidx, align 126  %inc = add nsw i32 %i.08, 127  %exitcond = icmp eq i32 %i.08, %bound28  br i1 %exitcond, label %for.end, label %for.body, !prof !129 30for.end:                                          ; preds = %for.body31  ret i32 032}33 34define i32 @foo_low_trip_count2(i32 %bound) !prof !0 {35; The loop has a same invocation count with the function, but has a low36; trip_count per invocation and not worth to vectorize.37 38; CHECK-LABEL: @foo_low_trip_count2(39; CHECK-NOT: <{{[0-9]+}} x i8>40 41entry:42  br label %for.body43 44for.body:                                         ; preds = %for.body, %entry45  %i.08 = phi i32 [ 0, %entry ], [ %inc, %for.body ]46  %arrayidx = getelementptr inbounds [32 x i8], ptr @tab, i32 0, i32 %i.0847  %0 = load i8, ptr %arrayidx, align 148  %cmp1 = icmp eq i8 %0, 049  %. = select i1 %cmp1, i8 2, i8 150  store i8 %., ptr %arrayidx, align 151  %inc = add nsw i32 %i.08, 152  %exitcond = icmp eq i32 %i.08, %bound53  br i1 %exitcond, label %for.end, label %for.body, !prof !154 55for.end:                                          ; preds = %for.body56  ret i32 057}58 59define i32 @foo_low_trip_count3(i1 %cond, i32 %bound) !prof !0 {60; The loop has low invocation count compare to the function invocation count,61; but has a high trip count per invocation. Vectorize it.62 63; CHECK-LABEL: @foo_low_trip_count3(64; CHECK:  [[VECTOR_BODY:vector\.body]]:65; CHECK:    br i1 [[TMP9:%.*]], label [[MIDDLE_BLOCK:%.*]], label %[[VECTOR_BODY]], !prof [[LP3:\!.*]],66; CHECK:  [[FOR_BODY:for\.body]]:67; CHECK:    br i1 [[EXITCOND:%.*]], label [[FOR_END_LOOPEXIT:%.*]], label %[[FOR_BODY]], !prof [[LP6:\!.*]],68entry:69  br i1 %cond, label %for.preheader, label %for.end, !prof !270 71for.preheader:72  br label %for.body73 74for.body:                                         ; preds = %for.body, %entry75  %i.08 = phi i32 [ 0, %for.preheader ], [ %inc, %for.body ]76  %arrayidx = getelementptr inbounds [32 x i8], ptr @tab, i32 0, i32 %i.0877  %0 = load i8, ptr %arrayidx, align 178  %cmp1 = icmp eq i8 %0, 079  %. = select i1 %cmp1, i8 2, i8 180  store i8 %., ptr %arrayidx, align 181  %inc = add nsw i32 %i.08, 182  %exitcond = icmp eq i32 %i.08, %bound83  br i1 %exitcond, label %for.end, label %for.body, !prof !384 85for.end:                                          ; preds = %for.body86  ret i32 087}88 89define i32 @foo_low_trip_count_icmp_sgt(i32 %bound) {90; Simple loop with low tripcount and inequality test for exit.91; Should not be vectorized.92 93; CHECK-LABEL: @foo_low_trip_count_icmp_sgt(94; CHECK-NOT: <{{[0-9]+}} x i8>95 96entry:97  br label %for.body98 99for.body:                                         ; preds = %for.body, %entry100  %i.08 = phi i32 [ 0, %entry ], [ %inc, %for.body ]101  %arrayidx = getelementptr inbounds [32 x i8], ptr @tab, i32 0, i32 %i.08102  %0 = load i8, ptr %arrayidx, align 1103  %cmp1 = icmp eq i8 %0, 0104  %. = select i1 %cmp1, i8 2, i8 1105  store i8 %., ptr %arrayidx, align 1106  %inc = add nsw i32 %i.08, 1107  %exitcond = icmp sgt i32 %i.08, %bound108  br i1 %exitcond, label %for.end, label %for.body, !prof !1109 110for.end:                                          ; preds = %for.body111  ret i32 0112}113 114define i32 @const_low_trip_count() {115; Simple loop with constant, small trip count and no profiling info.116 117; CHECK-LABEL: @const_low_trip_count118; CHECK-NOT: <{{[0-9]+}} x i8>119 120entry:121  br label %for.body122 123for.body:                                         ; preds = %for.body, %entry124  %i.08 = phi i32 [ 0, %entry ], [ %inc, %for.body ]125  %arrayidx = getelementptr inbounds [32 x i8], ptr @tab, i32 0, i32 %i.08126  %0 = load i8, ptr %arrayidx, align 1127  %cmp1 = icmp eq i8 %0, 0128  %. = select i1 %cmp1, i8 2, i8 1129  store i8 %., ptr %arrayidx, align 1130  %inc = add nsw i32 %i.08, 1131  %exitcond = icmp slt i32 %i.08, 2132  br i1 %exitcond, label %for.body, label %for.end133 134for.end:                                          ; preds = %for.body135  ret i32 0136}137 138define i32 @const_large_trip_count() {139; Simple loop with constant large trip count and no profiling info.140 141; CHECK-LABEL: @const_large_trip_count142; CHECK: <{{[0-9]+}} x i8>143 144entry:145  br label %for.body146 147for.body:                                         ; preds = %for.body, %entry148  %i.08 = phi i32 [ 0, %entry ], [ %inc, %for.body ]149  %arrayidx = getelementptr inbounds [32 x i8], ptr @tab, i32 0, i32 %i.08150  %0 = load i8, ptr %arrayidx, align 1151  %cmp1 = icmp eq i8 %0, 0152  %. = select i1 %cmp1, i8 2, i8 1153  store i8 %., ptr %arrayidx, align 1154  %inc = add nsw i32 %i.08, 1155  %exitcond = icmp slt i32 %i.08, 1000156  br i1 %exitcond, label %for.body, label %for.end157 158for.end:                                          ; preds = %for.body159  ret i32 0160}161 162define i32 @const_small_trip_count_step() {163; Simple loop with static, small trip count and no profiling info.164 165; CHECK-LABEL: @const_small_trip_count_step166; CHECK-NOT: <{{[0-9]+}} x i8>167 168entry:169  br label %for.body170 171for.body:                                         ; preds = %for.body, %entry172  %i.08 = phi i32 [ 0, %entry ], [ %inc, %for.body ]173  %arrayidx = getelementptr inbounds [32 x i8], ptr @tab, i32 0, i32 %i.08174  %0 = load i8, ptr %arrayidx, align 1175  %cmp1 = icmp eq i8 %0, 0176  %. = select i1 %cmp1, i8 2, i8 1177  store i8 %., ptr %arrayidx, align 1178  %inc = add nsw i32 %i.08, 5179  %exitcond = icmp slt i32 %i.08, 10180  br i1 %exitcond, label %for.body, label %for.end181 182for.end:                                          ; preds = %for.body183  ret i32 0184}185 186define i32 @const_trip_over_profile() {187; constant trip count takes precedence over profile data188 189; CHECK-LABEL: @const_trip_over_profile190; CHECK: <{{[0-9]+}} x i8>191 192entry:193  br label %for.body194 195for.body:                                         ; preds = %for.body, %entry196  %i.08 = phi i32 [ 0, %entry ], [ %inc, %for.body ]197  %arrayidx = getelementptr inbounds [32 x i8], ptr @tab, i32 0, i32 %i.08198  %0 = load i8, ptr %arrayidx, align 1199  %cmp1 = icmp eq i8 %0, 0200  %. = select i1 %cmp1, i8 2, i8 1201  store i8 %., ptr %arrayidx, align 1202  %inc = add nsw i32 %i.08, 1203  %exitcond = icmp slt i32 %i.08, 1000204  br i1 %exitcond, label %for.body, label %for.end, !prof !1205 206for.end:                                          ; preds = %for.body207  ret i32 0208}209 210; CHECK: [[LP3]] = !{!"branch_weights", i32 10, i32 2490}211; CHECK: [[LP6]] = !{!"branch_weights", i32 10, i32 0}212; original loop has latchExitWeight=10 and backedgeTakenWeight=10,000,213; therefore estimatedBackedgeTakenCount=1,000 and estimatedTripCount=1,001.214; Vectorizing by 4 produces estimatedTripCounts of 1,001/4=250 and 1,001%4=1215; for vectorized and remainder loops, respectively, therefore their216; estimatedBackedgeTakenCounts are 249 and 0, and so the weights recorded with217; loop invocation weights of 10 are the above {10, 2490} and {10, 0}.218 219!0 = !{!"function_entry_count", i64 100}220!1 = !{!"branch_weights", i32 100, i32 0}221!2 = !{!"branch_weights", i32 10, i32 90}222!3 = !{!"branch_weights", i32 10, i32 10000}223