| Issue |
179522
|
| Summary |
loop-vectorize missing profile information propagation
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
zBION1C
|
In the following IR code, some of the blocks created by running `loop-vectorize` have no profile metadata attached, which further leads to incorrect block frequencies (BFI analysis) on subsequent blocks as noted by manual inspection.
We reproduced this issue at commit [79eb804](https://github.com/llvm/llvm-project/commit/79eb804954bee06a62a3d31c697652f6dce982b1).
We provide an LLVM test to be run with `lit` that reproduces the issue when applying `loop-vectorize` to the test program. This test is a minimized form of the issue as it appeared when studying `-O3` optimization of a larger profiled program.
```llvm
; RUN: opt < %s -S -passes='loop-vectorize' \
; RUN: -vectorize-num-stores-pred=2 \
; RUN: -prefer-predicate-over-epilogue=predicate-dont-vectorize \
; RUN: -o - | FileCheck %s
; This checks the presence of profile metadata on branch in the vector.body basic block
; CHECK: vector.body: ; preds = %pred.store.continue2, %vector.ph
; CHECK: %index = phi i64 [ 0, %vector.ph ], [ %index.next, %pred.store.continue2 ]
; CHECK: %vec.ind = phi <2 x i8> [ <i8 0, i8 1>, %vector.ph ], [ %vec.ind.next, %pred.store.continue2 ]
; CHECK: %0 = icmp ule <2 x i8> %vec.ind, splat (i8 9)
; CHECK: %1 = extractelement <2 x i1> %0, i32 0
; CHECK: br i1 %1, label %pred.store.if, label %pred.store.continue, !prof ![[PROF1:[0-9]+]]
; This checks the presence of profile metadata on branch in the pred.store.continue basic block
; CHECK: pred.store.continue: ; preds = %pred.store.if, %vector.body
; CHECK: %4 = extractelement <2 x i1> %0, i32 1
; CHECK: br i1 %4, label %pred.store.if1, label %pred.store.continue2, !prof ![[PROF2:[0-9]+]]
; ModuleID = '/root/prog.ll'
source_filename = "/root/prog.c"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
@a = dso_local local_unnamed_addr global i16 0, align 2
@c = dso_local local_unnamed_addr global i8 0, align 1
@b = dso_local local_unnamed_addr global [10 x [10 x i32]] zeroinitializer, align 16
; Function Attrs: inlinehint nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none, target_mem0: none, target_mem1: none) uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 !prof !46 {
bb:
%i = load i16, ptr @a, align 2, !tbaa !39
%i1 = icmp slt i16 %i, 10
br i1 %i1, label %bb2, label %bb15, !prof !47
bb2: ; preds = %bb
%i3 = sext i16 %i to i64
br label %bb4
bb4: ; preds = %bb11, %bb2
%i5 = phi i64 [ %i3, %bb2 ], [ %i12, %bb11 ]
%i6 = getelementptr inbounds [10 x i32], ptr @b, i64 %i5
br label %._crit_edge
._crit_edge: ; preds = %._crit_edge, %bb4
%i7 = phi i64 [ 0, %bb4 ], [ %i9, %._crit_edge ]
%i8 = getelementptr inbounds nuw i32, ptr %i6, i64 %i7
store i32 1, ptr %i8, align 4, !tbaa !34
%i9 = add nuw nsw i64 %i7, 1
%i10 = icmp eq i64 %i9, 10
br i1 %i10, label %bb11, label %._crit_edge, !prof !48, !llvm.loop !41
bb11: ; preds = %._crit_edge
%i12 = add nsw i64 %i5, 1
%i13 = icmp eq i64 %i12, 10
br i1 %i13, label %bb14, label %bb4, !prof !49, !llvm.loop !44
bb14: ; preds = %bb11
store i8 10, ptr @c, align 1, !tbaa !45
store i16 10, ptr @a, align 2, !tbaa !39
br label %bb15
bb15: ; preds = %bb14, %bb
ret i32 0
}
attributes #0 = { cold nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none, target_mem0: none, target_mem1: none) uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { inlinehint nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none, target_mem0: none, target_mem1: none) uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
!llvm.module.flags = !{!0, !1, !2, !3, !4}
!llvm.ident = !{!33}
!llvm.errno.tbaa = !{!34}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{i32 1, !"ProfileSummary", !5}
!5 = !{!6, !7, !8, !9, !10, !11, !12, !13, !14, !15}
!6 = !{!"ProfileFormat", !"InstrProf"}
!7 = !{!"TotalCount", i64 5100}
!8 = !{!"MaxCount", i64 4500}
!9 = !{!"MaxInternalCount", i64 500}
!10 = !{!"MaxFunctionCount", i64 4500}
!11 = !{!"NumCounts", i64 8}
!12 = !{!"NumFunctions", i64 2}
!13 = !{!"IsPartialProfile", i64 0}
!14 = !{!"PartialProfileRatio", double 0.000000e+00}
!15 = !{!"DetailedSummary", !16}
!16 = !{!17, !18, !19, !20, !21, !22, !23, !24, !25, !26, !27, !28, !29, !30, !31, !32}
!17 = !{i32 10000, i64 4500, i32 1}
!18 = !{i32 100000, i64 4500, i32 1}
!19 = !{i32 200000, i64 4500, i32 1}
!20 = !{i32 300000, i64 4500, i32 1}
!21 = !{i32 400000, i64 4500, i32 1}
!22 = !{i32 500000, i64 4500, i32 1}
!23 = !{i32 600000, i64 4500, i32 1}
!24 = !{i32 700000, i64 4500, i32 1}
!25 = !{i32 800000, i64 4500, i32 1}
!26 = !{i32 900000, i64 500, i32 2}
!27 = !{i32 950000, i64 500, i32 2}
!28 = !{i32 990000, i64 50, i32 4}
!29 = !{i32 999000, i64 50, i32 4}
!30 = !{i32 999900, i64 50, i32 4}
!31 = !{i32 999990, i64 50, i32 4}
!32 = !{i32 999999, i64 50, i32 4}
!33 = !{!"clang version 22.0.0git (https://github.com/llvm/llvm-project.git 79eb804954bee06a62a3d31c697652f6dce982b1)"}
!34 = !{!35, !35, i64 0}
!35 = !{!"int", !36, i64 0}
!36 = !{!"omnipotent char", !37, i64 0}
!37 = !{!"Simple C/C++ TBAA"}
!38 = !{!"function_entry_count", i64 0}
!39 = !{!40, !40, i64 0}
!40 = !{!"short", !36, i64 0}
!41 = distinct !{!41, !42, !43}
!42 = !{!"llvm.loop.mustprogress"}
!43 = !{!"llvm.loop.unroll.disable"}
!44 = distinct !{!44, !42, !43}
!45 = !{!36, !36, i64 0}
!46 = !{!"function_entry_count", i64 50}
!47 = !{!"branch_weights", i32 50, i32 0}
!48 = !{!"branch_weights", i32 500, i32 4500}
!49 = !{!"branch_weights", i32 50, i32 450}
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs