When a vectorized loop has constant trip, it's important to update the profile information accordingly. Hotness analysis will only look at profile info. For example, in the `tripcount.ll` test, without producing the profile info, in the `const_trip_over_profile` function, the BFI of the `vector.body` would be 32 (this is the expected value when synthetic branch weights are used, in loops). The real value is 250. The `for.body`value was _very_ incorrect before, too (and detrimentally so, as it would have appeared as "very hot" when it wasn't): The table below was obtained by printing BFI in the RUN: command, i.e. `build/bin/opt < llvm/test/Transforms/LoopVectorize/tripcount.ll -passes="loop-vectorize,print<block-freq>" -loop-vectorize-with-block-frequency -S -o /dev/null`. Showing only the `float` value, i.e. the BFI relative to the function entry BB. ``` Printing analysis results of BFI for function 'const_trip_over_profile': block-frequency-info: const_trip_over_profile ``` | Block | Before | After | | ----- | ------ | ----- | | `entry` | float = 1.0 | float = 1.0 | | `vector.ph` | float = 1.0 | float = 1.0 | | `vector.body` | float = **32.0** | float = **250.0** | | `middle.block` | float = 1.0 | float = 1.0 | | `scalar.ph` | float = 1.0 | float = 1.0 | | `for.body` | float = **2147483647.8** | float = **1.0** | | `for.end` | float = 1.0 | float = 1.0 |
51 lines
2.2 KiB
LLVM
51 lines
2.2 KiB
LLVM
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals all --version 6
|
|
; RUN: opt < %s -passes=loop-vectorize -force-vector-width=4 -S | FileCheck %s
|
|
|
|
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
|
|
|
|
define void @lshr_exact(ptr %x) !prof !{!"function_entry_count", i32 1} {
|
|
; CHECK-LABEL: define void @lshr_exact(
|
|
; CHECK-SAME: ptr [[X:%.*]]) !prof [[PROF0:![0-9]+]] {
|
|
; CHECK-NEXT: [[ENTRY:.*:]]
|
|
; CHECK-NEXT: br label %[[VECTOR_PH:.*]]
|
|
; CHECK: [[VECTOR_PH]]:
|
|
; CHECK-NEXT: br label %[[VECTOR_BODY:.*]]
|
|
; CHECK: [[VECTOR_BODY]]:
|
|
; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
|
|
; CHECK-NEXT: [[TMP0:%.*]] = getelementptr inbounds i32, ptr [[X]], i64 [[INDEX]]
|
|
; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <4 x i32>, ptr [[TMP0]], align 4
|
|
; CHECK-NEXT: [[TMP1:%.*]] = lshr exact <4 x i32> [[WIDE_LOAD]], splat (i32 1)
|
|
; CHECK-NEXT: store <4 x i32> [[TMP1]], ptr [[TMP0]], align 4
|
|
; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
|
|
; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i64 [[INDEX_NEXT]], 256
|
|
; CHECK-NEXT: br i1 [[TMP2]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !prof [[PROF1:![0-9]+]], !llvm.loop [[LOOP2:![0-9]+]]
|
|
; CHECK: [[MIDDLE_BLOCK]]:
|
|
; CHECK-NEXT: br label %[[FOR_END:.*]]
|
|
; CHECK: [[FOR_END]]:
|
|
; CHECK-NEXT: ret void
|
|
;
|
|
entry:
|
|
br label %for.body
|
|
|
|
for.body:
|
|
%iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
|
|
%arrayidx = getelementptr inbounds i32, ptr %x, i64 %iv
|
|
%0 = load i32, ptr %arrayidx, align 4
|
|
%conv1 = lshr exact i32 %0, 1
|
|
store i32 %conv1, ptr %arrayidx, align 4
|
|
%iv.next = add nuw nsw i64 %iv, 1
|
|
%exitcond = icmp eq i64 %iv.next, 256
|
|
br i1 %exitcond, label %for.end, label %for.body
|
|
|
|
for.end:
|
|
ret void
|
|
}
|
|
;.
|
|
; CHECK: [[PROF0]] = !{!"function_entry_count", i32 1}
|
|
; CHECK: [[PROF1]] = !{!"branch_weights", i32 1, i32 63}
|
|
; CHECK: [[LOOP2]] = distinct !{[[LOOP2]], [[META3:![0-9]+]], [[META4:![0-9]+]], [[META5:![0-9]+]]}
|
|
; CHECK: [[META3]] = !{!"llvm.loop.isvectorized", i32 1}
|
|
; CHECK: [[META4]] = !{!"llvm.loop.unroll.runtime.disable"}
|
|
; CHECK: [[META5]] = !{!"llvm.loop.estimated_trip_count", i32 64}
|
|
;.
|