Taewook Oh | 9083547 | 2017-06-19 18:48:58 +0000 | [diff] [blame] | 1 | ; This test verifies that the loop vectorizer will not vectorizes low trip count |
| 2 | ; loops that require runtime checks (Trip count is computed with profile info). |
| 3 | ; REQUIRES: asserts |
| 4 | ; RUN: opt < %s -loop-vectorize -loop-vectorize-with-block-frequency -S | FileCheck %s |
| 5 | |
| 6 | target 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 1 |
| 9 | |
| 10 | define 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 | |
| 16 | entry: |
| 17 | br label %for.body |
| 18 | |
| 19 | for.body: ; preds = %for.body, %entry |
| 20 | %i.08 = phi i32 [ 0, %entry ], [ %inc, %for.body ] |
| 21 | %arrayidx = getelementptr inbounds [32 x i8], [32 x i8]* @tab, i32 0, i32 %i.08 |
| 22 | %0 = load i8, i8* %arrayidx, align 1 |
| 23 | %cmp1 = icmp eq i8 %0, 0 |
| 24 | %. = select i1 %cmp1, i8 2, i8 1 |
| 25 | store i8 %., i8* %arrayidx, align 1 |
| 26 | %inc = add nsw i32 %i.08, 1 |
| 27 | %exitcond = icmp eq i32 %i.08, %bound |
| 28 | br i1 %exitcond, label %for.end, label %for.body, !prof !1 |
| 29 | |
| 30 | for.end: ; preds = %for.body |
| 31 | ret i32 0 |
| 32 | } |
| 33 | |
| 34 | define i32 @foo_low_trip_count2(i32 %bound) !prof !0 { |
| 35 | ; The loop has a same invocation count with the function, but has a low |
| 36 | ; 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 | |
| 41 | entry: |
| 42 | br label %for.body |
| 43 | |
| 44 | for.body: ; preds = %for.body, %entry |
| 45 | %i.08 = phi i32 [ 0, %entry ], [ %inc, %for.body ] |
| 46 | %arrayidx = getelementptr inbounds [32 x i8], [32 x i8]* @tab, i32 0, i32 %i.08 |
| 47 | %0 = load i8, i8* %arrayidx, align 1 |
| 48 | %cmp1 = icmp eq i8 %0, 0 |
| 49 | %. = select i1 %cmp1, i8 2, i8 1 |
| 50 | store i8 %., i8* %arrayidx, align 1 |
| 51 | %inc = add nsw i32 %i.08, 1 |
| 52 | %exitcond = icmp eq i32 %i.08, %bound |
| 53 | br i1 %exitcond, label %for.end, label %for.body, !prof !1 |
| 54 | |
| 55 | for.end: ; preds = %for.body |
| 56 | ret i32 0 |
| 57 | } |
| 58 | |
| 59 | define 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: |
| 65 | |
| 66 | entry: |
| 67 | br i1 %cond, label %for.preheader, label %for.end, !prof !2 |
| 68 | |
| 69 | for.preheader: |
| 70 | br label %for.body |
| 71 | |
| 72 | for.body: ; preds = %for.body, %entry |
| 73 | %i.08 = phi i32 [ 0, %for.preheader ], [ %inc, %for.body ] |
| 74 | %arrayidx = getelementptr inbounds [32 x i8], [32 x i8]* @tab, i32 0, i32 %i.08 |
| 75 | %0 = load i8, i8* %arrayidx, align 1 |
| 76 | %cmp1 = icmp eq i8 %0, 0 |
| 77 | %. = select i1 %cmp1, i8 2, i8 1 |
| 78 | store i8 %., i8* %arrayidx, align 1 |
| 79 | %inc = add nsw i32 %i.08, 1 |
| 80 | %exitcond = icmp eq i32 %i.08, %bound |
| 81 | br i1 %exitcond, label %for.end, label %for.body, !prof !3 |
| 82 | |
| 83 | for.end: ; preds = %for.body |
| 84 | ret i32 0 |
| 85 | } |
| 86 | |
| 87 | |
| 88 | !0 = !{!"function_entry_count", i64 100} |
| 89 | !1 = !{!"branch_weights", i32 100, i32 0} |
| 90 | !2 = !{!"branch_weights", i32 10, i32 90} |
| 91 | !3 = !{!"branch_weights", i32 10, i32 10000} |