Skip to content

Commit e662894

Browse files
committed
[DebugInfo][LoopVectorizer] Avoid dropping !dbg in optimizeForVFAndUF
Prior to this patch, optimizeForVFAndUF may optimize the branch condition for a VPBasicblock to a constant, but unnecessarily drops the DILocation attachment when it does so; this patch changes it to preserve the DILocation.
1 parent fcfd643 commit e662894

File tree

2 files changed

+109
-1
lines changed

2 files changed

+109
-1
lines changed

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ void VPlanTransforms::optimizeForVFAndUF(VPlan &Plan, ElementCount BestVF,
699699
LLVMContext &Ctx = SE.getContext();
700700
auto *BOC =
701701
new VPInstruction(VPInstruction::BranchOnCond,
702-
{Plan.getOrAddLiveIn(ConstantInt::getTrue(Ctx))});
702+
{Plan.getOrAddLiveIn(ConstantInt::getTrue(Ctx))}, Term->getDebugLoc());
703703

704704
SmallVector<VPValue *> PossiblyDead(Term->operands());
705705
Term->eraseFromParent();
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -S < %s -passes=loop-vectorize -force-vector-width=2 | FileCheck %s
3+
4+
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"
5+
target triple = "x86_64-unknown-linux-gnu"
6+
7+
define fastcc i32 @foo(i64 %a) {
8+
; CHECK-LABEL: define fastcc i32 @foo(
9+
; CHECK-SAME: i64 [[A:%.*]]) {
10+
; CHECK-NEXT: [[ENTRY:.*]]:
11+
; CHECK-NEXT: [[WIDE_TRIP_COUNT:%.*]] = and i64 [[A]], 1
12+
; CHECK-NEXT: [[TMP0:%.*]] = add nuw nsw i64 [[WIDE_TRIP_COUNT]], 1
13+
; CHECK-NEXT: br i1 false, label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]]
14+
; CHECK: [[VECTOR_PH]]:
15+
; CHECK-NEXT: [[N_RND_UP:%.*]] = add i64 [[TMP0]], 1
16+
; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[N_RND_UP]], 2
17+
; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[N_RND_UP]], [[N_MOD_VF]]
18+
; CHECK-NEXT: [[TRIP_COUNT_MINUS_1:%.*]] = sub i64 [[TMP0]], 1
19+
; CHECK-NEXT: [[BROADCAST_SPLATINSERT1:%.*]] = insertelement <2 x i64> poison, i64 [[TRIP_COUNT_MINUS_1]], i64 0
20+
; CHECK-NEXT: [[BROADCAST_SPLAT2:%.*]] = shufflevector <2 x i64> [[BROADCAST_SPLATINSERT1]], <2 x i64> poison, <2 x i32> zeroinitializer
21+
; CHECK-NEXT: br label %[[VECTOR_BODY:.*]]
22+
; CHECK: [[VECTOR_BODY]]:
23+
; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[PRED_STORE_CONTINUE4:.*]] ], !dbg [[DBG4:![0-9]+]]
24+
; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <2 x i64> poison, i64 [[INDEX]], i64 0
25+
; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <2 x i64> [[BROADCAST_SPLATINSERT]], <2 x i64> poison, <2 x i32> zeroinitializer
26+
; CHECK-NEXT: [[VEC_IV:%.*]] = add <2 x i64> [[BROADCAST_SPLAT]], <i64 0, i64 1>
27+
; CHECK-NEXT: [[TMP1:%.*]] = icmp ule <2 x i64> [[VEC_IV]], [[BROADCAST_SPLAT2]]
28+
; CHECK-NEXT: [[TMP2:%.*]] = extractelement <2 x i1> [[TMP1]], i32 0
29+
; CHECK-NEXT: br i1 [[TMP2]], label %[[PRED_STORE_IF:.*]], label %[[PRED_STORE_CONTINUE:.*]]
30+
; CHECK: [[PRED_STORE_IF]]:
31+
; CHECK-NEXT: [[TMP3:%.*]] = trunc i64 0 to i8, !dbg [[DBG8:![0-9]+]]
32+
; CHECK-NEXT: store i8 [[TMP3]], ptr null, align 1, !dbg [[DBG9:![0-9]+]]
33+
; CHECK-NEXT: br label %[[PRED_STORE_CONTINUE]]
34+
; CHECK: [[PRED_STORE_CONTINUE]]:
35+
; CHECK-NEXT: [[TMP4:%.*]] = extractelement <2 x i1> [[TMP1]], i32 1, !dbg [[DBG9]]
36+
; CHECK-NEXT: br i1 [[TMP4]], label %[[PRED_STORE_IF3:.*]], label %[[PRED_STORE_CONTINUE4]], !dbg [[DBG9]]
37+
; CHECK: [[PRED_STORE_IF3]]:
38+
; CHECK-NEXT: [[TMP5:%.*]] = trunc i64 0 to i8, !dbg [[DBG8]]
39+
; CHECK-NEXT: store i8 [[TMP5]], ptr null, align 1, !dbg [[DBG9]]
40+
; CHECK-NEXT: br label %[[PRED_STORE_CONTINUE4]], !dbg [[DBG9]]
41+
; CHECK: [[PRED_STORE_CONTINUE4]]:
42+
; CHECK-NEXT: [[INDEX_NEXT]] = add i64 [[INDEX]], 2, !dbg [[DBG4]]
43+
; CHECK-NEXT: br i1 true, label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !dbg [[DBG4]], !llvm.loop [[LOOP10:![0-9]+]]
44+
; CHECK: [[MIDDLE_BLOCK]]:
45+
; CHECK-NEXT: br i1 true, label %[[DO_BODY45_PREHEADER:.*]], label %[[SCALAR_PH]], !dbg [[DBG13:![0-9]+]]
46+
; CHECK: [[SCALAR_PH]]:
47+
; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], %[[MIDDLE_BLOCK]] ], [ 0, %[[ENTRY]] ], !dbg [[DBG4]]
48+
; CHECK-NEXT: br label %[[DO_BODY:.*]]
49+
; CHECK: [[DO_BODY]]:
50+
; CHECK-NEXT: [[INDVARS_IV554:%.*]] = phi i64 [ [[INDVARS_IV_NEXT555:%.*]], %[[DO_BODY]] ], [ [[BC_RESUME_VAL]], %[[SCALAR_PH]] ], !dbg [[DBG4]]
51+
; CHECK-NEXT: [[CONV39:%.*]] = trunc i64 0 to i8, !dbg [[DBG8]]
52+
; CHECK-NEXT: store i8 [[CONV39]], ptr null, align 1, !dbg [[DBG9]]
53+
; CHECK-NEXT: [[INDVARS_IV_NEXT555]] = add i64 [[INDVARS_IV554]], 1, !dbg [[DBG14:![0-9]+]]
54+
; CHECK-NEXT: [[EXITCOND557_NOT:%.*]] = icmp eq i64 [[INDVARS_IV554]], [[WIDE_TRIP_COUNT]], !dbg [[DBG15:![0-9]+]]
55+
; CHECK-NEXT: br i1 [[EXITCOND557_NOT]], label %[[DO_BODY45_PREHEADER]], label %[[DO_BODY]], !dbg [[DBG13]], !llvm.loop [[LOOP16:![0-9]+]]
56+
; CHECK: [[DO_BODY45_PREHEADER]]:
57+
; CHECK-NEXT: ret i32 0
58+
;
59+
entry:
60+
%wide.trip.count = and i64 %a, 1
61+
br label %do.body
62+
63+
do.body: ; preds = %do.body, %entry
64+
%indvars.iv554 = phi i64 [ %indvars.iv.next555, %do.body ], [ 0, %entry ], !dbg !4
65+
%conv39 = trunc i64 0 to i8, !dbg !5
66+
store i8 %conv39, ptr null, align 1, !dbg !6
67+
%indvars.iv.next555 = add i64 %indvars.iv554, 1, !dbg !7
68+
%exitcond557.not = icmp eq i64 %indvars.iv554, %wide.trip.count, !dbg !8
69+
br i1 %exitcond557.not, label %do.body45.preheader, label %do.body, !dbg !9
70+
71+
do.body45.preheader: ; preds = %do.body
72+
ret i32 0
73+
}
74+
75+
!llvm.dbg.cu = !{!0}
76+
!llvm.module.flags = !{!3}
77+
78+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 20.0.0git (https://github.com/llvm/llvm-project.git 97cea5fecc5fa70842644da877c9547d4f34f6db)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !2, imports: !2, splitDebugInlining: false, nameTableKind: None)
79+
!1 = !DIFile(filename: "/home/gbtozers/dev/llvm-test-suite/CTMark/7zip/CPP/7zip/Compress/BZip2Decoder.cpp", directory: "/home/gbtozers/dev/llvm-test-suite-build", checksumkind: CSK_MD5, checksum: "ace37523c35f8079a0f00d337fc014dc")
80+
!2 = !{}
81+
!3 = !{i32 2, !"Debug Info Version", i32 3}
82+
!4 = !DILocation(line: 4, scope: !21)
83+
!5 = !DILocation(line: 5, scope: !21)
84+
!6 = !DILocation(line: 6, scope: !21)
85+
!7 = !DILocation(line: 7, scope: !21)
86+
!8 = !DILocation(line: 8, scope: !21)
87+
!9 = !DILocation(line: 9, scope: !21)
88+
!20 = !DIFile(filename: "llvm-test-suite/CTMark/7zip/CPP/7zip/Compress/BZip2Decoder.cpp", directory: "/home/gbtozers/dev", checksumkind: CSK_MD5, checksum: "ace37523c35f8079a0f00d337fc014dc")
89+
!21 = distinct !DISubprogram(name: "ReadBlock", linkageName: "foo", scope: !20, file: !20, line: 113, type: !22, scopeLine: 116, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
90+
!22 = distinct !DISubroutineType(types: !2)
91+
;.
92+
; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: [[META1:![0-9]+]], producer: "{{.*}}clang version {{.*}}", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: [[META2:![0-9]+]], retainedTypes: [[META2]], globals: [[META2]], imports: [[META2]], splitDebugInlining: false, nameTableKind: None)
93+
; CHECK: [[META1]] = !DIFile(filename: "/home/gbtozers/dev/llvm-test-suite/CTMark/7zip/CPP/7zip/Compress/BZip2Decoder.cpp", directory: {{.*}})
94+
; CHECK: [[META2]] = !{}
95+
; CHECK: [[DBG4]] = !DILocation(line: 4, scope: [[META5:![0-9]+]])
96+
; CHECK: [[META5]] = distinct !DISubprogram(name: "ReadBlock", linkageName: "foo", scope: [[META6:![0-9]+]], file: [[META6]], line: 113, type: [[META7:![0-9]+]], scopeLine: 116, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: [[META0]], retainedNodes: [[META2]])
97+
; CHECK: [[META6]] = !DIFile(filename: "llvm-test-suite/CTMark/7zip/CPP/7zip/Compress/BZip2Decoder.cpp", directory: {{.*}})
98+
; CHECK: [[META7]] = distinct !DISubroutineType(types: [[META2]])
99+
; CHECK: [[DBG8]] = !DILocation(line: 5, scope: [[META5]])
100+
; CHECK: [[DBG9]] = !DILocation(line: 6, scope: [[META5]])
101+
; CHECK: [[LOOP10]] = distinct !{[[LOOP10]], [[META11:![0-9]+]], [[META12:![0-9]+]]}
102+
; CHECK: [[META11]] = !{!"llvm.loop.isvectorized", i32 1}
103+
; CHECK: [[META12]] = !{!"llvm.loop.unroll.runtime.disable"}
104+
; CHECK: [[DBG13]] = !DILocation(line: 9, scope: [[META5]])
105+
; CHECK: [[DBG14]] = !DILocation(line: 7, scope: [[META5]])
106+
; CHECK: [[DBG15]] = !DILocation(line: 8, scope: [[META5]])
107+
; CHECK: [[LOOP16]] = distinct !{[[LOOP16]], [[META12]], [[META11]]}
108+
;.

0 commit comments

Comments
 (0)