[llvm] b6e8f66 - [LV] Skipping all debug instructions when native vplan is enabled (#77413)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 15 19:08:14 PST 2024


Author: Mel Chen
Date: 2024-01-16T11:08:10+08:00
New Revision: b6e8f6604c1ca79e01d3db816c16101ae2834f60

URL: https://github.com/llvm/llvm-project/commit/b6e8f6604c1ca79e01d3db816c16101ae2834f60
DIFF: https://github.com/llvm/llvm-project/commit/b6e8f6604c1ca79e01d3db816c16101ae2834f60.diff

LOG: [LV] Skipping all debug instructions when native vplan is enabled (#77413)

The following internal error occurred when using native vplan to
vectorize the program with the debug info generation.

Assertion `!isa<DbgInfoIntrinsic>(CI) && "DbgInfoIntrinsic should have been dropped during VPlan construction"' failed.

This patch ignored all debug instructions to fix the error when native
vplan is enabled.

Added: 
    llvm/test/Transforms/LoopVectorize/dbg-outer-loop-vect.ll

Modified: 
    llvm/lib/Transforms/Vectorize/VPlanHCFGBuilder.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Vectorize/VPlanHCFGBuilder.cpp b/llvm/lib/Transforms/Vectorize/VPlanHCFGBuilder.cpp
index f950d4740e413c8..94456bf858d9c5c 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanHCFGBuilder.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanHCFGBuilder.cpp
@@ -283,7 +283,7 @@ VPValue *PlainCFGBuilder::getOrCreateVPOperand(Value *IRVal) {
 void PlainCFGBuilder::createVPInstructionsForVPBB(VPBasicBlock *VPBB,
                                                   BasicBlock *BB) {
   VPIRBuilder.setInsertPoint(VPBB);
-  for (Instruction &InstRef : *BB) {
+  for (Instruction &InstRef : BB->instructionsWithoutDebug(false)) {
     Instruction *Inst = &InstRef;
 
     // There shouldn't be any VPValue for Inst at this point. Otherwise, we

diff  --git a/llvm/test/Transforms/LoopVectorize/dbg-outer-loop-vect.ll b/llvm/test/Transforms/LoopVectorize/dbg-outer-loop-vect.ll
new file mode 100644
index 000000000000000..7f209634fe053d2
--- /dev/null
+++ b/llvm/test/Transforms/LoopVectorize/dbg-outer-loop-vect.ll
@@ -0,0 +1,176 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
+; RUN: opt < %s -S -passes=loop-vectorize -enable-vplan-native-path -force-vector-interleave=1 -force-vector-width=4 | FileCheck %s
+
+target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128"
+
+define void @foo(ptr %h) !dbg !4 {
+; CHECK-LABEL: define void @foo(
+; CHECK-SAME: ptr [[H:%.*]]) !dbg [[DBG4:![0-9]+]] {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    call void @llvm.dbg.value(metadata i64 0, metadata [[META11:![0-9]+]], metadata !DIExpression()), !dbg [[DBG20:![0-9]+]]
+; CHECK-NEXT:    br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]], !dbg [[DBG21:![0-9]+]]
+; CHECK:       vector.ph:
+; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]], !dbg [[DBG21]]
+; CHECK:       vector.body:
+; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[FOR_COND_CLEANUP32:%.*]] ]
+; CHECK-NEXT:    [[VEC_IND:%.*]] = phi <4 x i64> [ <i64 0, i64 1, i64 2, i64 3>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[FOR_COND_CLEANUP32]] ]
+; CHECK-NEXT:    br label [[FOR_COND5_PREHEADER1:%.*]], !dbg [[DBG21]]
+; CHECK:       for.cond5.preheader1:
+; CHECK-NEXT:    [[VEC_PHI:%.*]] = phi <4 x i64> [ zeroinitializer, [[VECTOR_BODY]] ], [ [[TMP4:%.*]], [[FOR_COND5_PREHEADER1]] ], !dbg [[DBG21]]
+; CHECK-NEXT:    [[TMP0:%.*]] = getelementptr i32, ptr [[H]], <4 x i64> [[VEC_PHI]], !dbg [[DBG21]]
+; CHECK-NEXT:    call void @llvm.masked.scatter.v4i32.v4p0(<4 x i32> zeroinitializer, <4 x ptr> [[TMP0]], i32 4, <4 x i1> <i1 true, i1 true, i1 true, i1 true>), !dbg [[DBG22:![0-9]+]]
+; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr i32, <4 x ptr> [[TMP0]], i64 1, !dbg [[DBG22]]
+; CHECK-NEXT:    call void @llvm.masked.scatter.v4i32.v4p0(<4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x ptr> [[TMP1]], i32 4, <4 x i1> <i1 true, i1 true, i1 true, i1 true>), !dbg [[DBG22]]
+; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr i32, <4 x ptr> [[TMP0]], i64 2, !dbg [[DBG22]]
+; CHECK-NEXT:    call void @llvm.masked.scatter.v4i32.v4p0(<4 x i32> <i32 2, i32 2, i32 2, i32 2>, <4 x ptr> [[TMP2]], i32 4, <4 x i1> <i1 true, i1 true, i1 true, i1 true>), !dbg [[DBG22]]
+; CHECK-NEXT:    [[TMP3:%.*]] = getelementptr i32, <4 x ptr> [[TMP0]], i64 3, !dbg [[DBG22]]
+; CHECK-NEXT:    call void @llvm.masked.scatter.v4i32.v4p0(<4 x i32> <i32 3, i32 3, i32 3, i32 3>, <4 x ptr> [[TMP3]], i32 4, <4 x i1> <i1 true, i1 true, i1 true, i1 true>), !dbg [[DBG22]]
+; CHECK-NEXT:    [[TMP4]] = add nuw nsw <4 x i64> [[VEC_PHI]], <i64 1, i64 1, i64 1, i64 1>, !dbg [[DBG24:![0-9]+]]
+; CHECK-NEXT:    [[TMP5:%.*]] = icmp eq <4 x i64> [[TMP4]], <i64 5, i64 5, i64 5, i64 5>, !dbg [[DBG25:![0-9]+]]
+; CHECK-NEXT:    [[TMP6:%.*]] = extractelement <4 x i1> [[TMP5]], i32 0
+; CHECK-NEXT:    br i1 [[TMP6]], label [[FOR_COND_CLEANUP32]], label [[FOR_COND5_PREHEADER1]]
+; CHECK:       for.cond.cleanup32:
+; CHECK-NEXT:    [[TMP7:%.*]] = add nuw nsw <4 x i64> [[VEC_IND]], <i64 1, i64 1, i64 1, i64 1>, !dbg [[DBG26:![0-9]+]]
+; CHECK-NEXT:    [[TMP8:%.*]] = icmp eq <4 x i64> [[TMP7]], <i64 23, i64 23, i64 23, i64 23>, !dbg [[DBG27:![0-9]+]]
+; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
+; CHECK-NEXT:    [[VEC_IND_NEXT]] = add <4 x i64> [[VEC_IND]], <i64 4, i64 4, i64 4, i64 4>
+; CHECK-NEXT:    [[TMP9:%.*]] = icmp eq i64 [[INDEX_NEXT]], 20
+; CHECK-NEXT:    br i1 [[TMP9]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP28:![0-9]+]]
+; CHECK:       middle.block:
+; CHECK-NEXT:    br i1 false, label [[EXIT:%.*]], label [[SCALAR_PH]], !dbg [[DBG21]]
+; CHECK:       scalar.ph:
+; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ 20, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
+; CHECK-NEXT:    br label [[FOR_COND1_PREHEADER:%.*]], !dbg [[DBG21]]
+; CHECK:       for.cond1.preheader:
+; CHECK-NEXT:    [[I_023:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[INC13:%.*]], [[FOR_COND_CLEANUP3:%.*]] ]
+; CHECK-NEXT:    call void @llvm.dbg.value(metadata i64 [[I_023]], metadata [[META11]], metadata !DIExpression()), !dbg [[DBG20]]
+; CHECK-NEXT:    br label [[FOR_COND5_PREHEADER:%.*]], !dbg [[DBG32:![0-9]+]]
+; CHECK:       for.cond5.preheader:
+; CHECK-NEXT:    [[L_022:%.*]] = phi i64 [ 0, [[FOR_COND1_PREHEADER]] ], [ [[INC10:%.*]], [[FOR_COND5_PREHEADER]] ]
+; CHECK-NEXT:    [[TMP10:%.*]] = getelementptr i32, ptr [[H]], i64 [[L_022]]
+; CHECK-NEXT:    store i32 0, ptr [[TMP10]], align 4, !dbg [[DBG22]]
+; CHECK-NEXT:    [[ARRAYIDX_1:%.*]] = getelementptr i32, ptr [[TMP10]], i64 1, !dbg [[DBG33:![0-9]+]]
+; CHECK-NEXT:    store i32 1, ptr [[ARRAYIDX_1]], align 4, !dbg [[DBG22]]
+; CHECK-NEXT:    [[ARRAYIDX_2:%.*]] = getelementptr i32, ptr [[TMP10]], i64 2, !dbg [[DBG33]]
+; CHECK-NEXT:    store i32 2, ptr [[ARRAYIDX_2]], align 4, !dbg [[DBG22]]
+; CHECK-NEXT:    [[ARRAYIDX_3:%.*]] = getelementptr i32, ptr [[TMP10]], i64 3, !dbg [[DBG33]]
+; CHECK-NEXT:    store i32 3, ptr [[ARRAYIDX_3]], align 4, !dbg [[DBG22]]
+; CHECK-NEXT:    [[INC10]] = add nuw nsw i64 [[L_022]], 1, !dbg [[DBG24]]
+; CHECK-NEXT:    [[EXITCOND_NOT:%.*]] = icmp eq i64 [[INC10]], 5, !dbg [[DBG25]]
+; CHECK-NEXT:    br i1 [[EXITCOND_NOT]], label [[FOR_COND_CLEANUP3]], label [[FOR_COND5_PREHEADER]], !dbg [[DBG32]]
+; CHECK:       for.cond.cleanup3:
+; CHECK-NEXT:    [[INC13]] = add nuw nsw i64 [[I_023]], 1, !dbg [[DBG26]]
+; CHECK-NEXT:    call void @llvm.dbg.value(metadata i64 [[INC13]], metadata [[META11]], metadata !DIExpression()), !dbg [[DBG20]]
+; CHECK-NEXT:    [[EXITCOND24_NOT:%.*]] = icmp eq i64 [[INC13]], 23, !dbg [[DBG27]]
+; CHECK-NEXT:    br i1 [[EXITCOND24_NOT]], label [[EXIT]], label [[FOR_COND1_PREHEADER]], !dbg [[DBG21]], !llvm.loop [[LOOP34:![0-9]+]]
+; CHECK:       exit:
+; CHECK-NEXT:    ret void, !dbg [[DBG35:![0-9]+]]
+;
+entry:
+  call void @llvm.dbg.value(metadata i64 0, metadata !11, metadata !DIExpression()), !dbg !20
+  br label %for.cond1.preheader, !dbg !21
+
+for.cond1.preheader:                              ; preds = %entry, %for.cond.cleanup3
+  %i.023 = phi i64 [ 0, %entry ], [ %inc13, %for.cond.cleanup3 ]
+  call void @llvm.dbg.value(metadata i64 %i.023, metadata !11, metadata !DIExpression()), !dbg !20
+  br label %for.cond5.preheader, !dbg !22
+
+for.cond5.preheader:                              ; preds = %for.cond1.preheader, %for.cond5.preheader
+  %l.022 = phi i64 [ 0, %for.cond1.preheader ], [ %inc10, %for.cond5.preheader ]
+  %0 = getelementptr i32, ptr %h, i64 %l.022
+  store i32 0, ptr %0, align 4, !dbg !24
+  %arrayidx.1 = getelementptr i32, ptr %0, i64 1, !dbg !26
+  store i32 1, ptr %arrayidx.1, align 4, !dbg !24
+  %arrayidx.2 = getelementptr i32, ptr %0, i64 2, !dbg !26
+  store i32 2, ptr %arrayidx.2, align 4, !dbg !24
+  %arrayidx.3 = getelementptr i32, ptr %0, i64 3, !dbg !26
+  store i32 3, ptr %arrayidx.3, align 4, !dbg !24
+  %inc10 = add nuw nsw i64 %l.022, 1, !dbg !27
+  %exitcond.not = icmp eq i64 %inc10, 5, !dbg !28
+  br i1 %exitcond.not, label %for.cond.cleanup3, label %for.cond5.preheader, !dbg !22
+
+for.cond.cleanup3:                                ; preds = %for.cond5.preheader
+  %inc13 = add nuw nsw i64 %i.023, 1, !dbg !29
+  call void @llvm.dbg.value(metadata i64 %inc13, metadata !11, metadata !DIExpression()), !dbg !20
+  %exitcond24.not = icmp eq i64 %inc13, 23, !dbg !30
+  br i1 %exitcond24.not, label %exit, label %for.cond1.preheader, !dbg !21, !llvm.loop !31
+
+exit:                                 ; preds = %for.cond.cleanup3
+  ret void, !dbg !23
+}
+
+declare void @llvm.dbg.value(metadata, metadata, metadata)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2, !3}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "outer-loop-vect.c", directory: "/test/file/path")
+!2 = !{i32 2, !"Debug Info Version", i32 3}
+!3 = !{i32 7, !"debug-info-assignment-tracking", i1 true}
+!4 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 8, type: !5, scopeLine: 8, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !9)
+!5 = !DISubroutineType(types: !6)
+!6 = !{null, !7}
+!7 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64)
+!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!9 = !{!10, !11, !14, !17}
+!10 = !DILocalVariable(name: "h", arg: 1, scope: !4, file: !1, line: 8, type: !7)
+!11 = !DILocalVariable(name: "i", scope: !12, file: !1, line: 10, type: !13)
+!12 = distinct !DILexicalBlock(scope: !4, file: !1, line: 10, column: 3)
+!13 = !DIBasicType(name: "unsigned long", size: 64, encoding: DW_ATE_unsigned)
+!14 = !DILocalVariable(name: "l", scope: !15, file: !1, line: 11, type: !13)
+!15 = distinct !DILexicalBlock(scope: !16, file: !1, line: 11, column: 5)
+!16 = distinct !DILexicalBlock(scope: !12, file: !1, line: 10, column: 3)
+!17 = !DILocalVariable(name: "j", scope: !18, file: !1, line: 12, type: !13)
+!18 = distinct !DILexicalBlock(scope: !19, file: !1, line: 12, column: 7)
+!19 = distinct !DILexicalBlock(scope: !15, file: !1, line: 11, column: 5)
+!20 = !DILocation(line: 0, scope: !12)
+!21 = !DILocation(line: 10, column: 3, scope: !12)
+!22 = !DILocation(line: 11, column: 5, scope: !15)
+!23 = !DILocation(line: 14, column: 1, scope: !4)
+!24 = !DILocation(line: 13, column: 11, scope: !25)
+!25 = distinct !DILexicalBlock(scope: !18, file: !1, line: 12, column: 7)
+!26 = !DILocation(line: 13, column: 2, scope: !25)
+!27 = !DILocation(line: 11, column: 32, scope: !19)
+!28 = !DILocation(line: 11, column: 26, scope: !19)
+!29 = !DILocation(line: 10, column: 30, scope: !16)
+!30 = !DILocation(line: 10, column: 24, scope: !16)
+!31 = distinct !{!31, !21, !32, !33}
+!32 = !DILocation(line: 13, column: 13, scope: !12)
+!33 = !{!"llvm.loop.vectorize.enable", i1 true}
+;.
+; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C11, file: [[META1:![0-9]+]], producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
+; CHECK: [[META1]] = !DIFile(filename: "outer-loop-vect.c", directory: {{.*}})
+; CHECK: [[DBG4]] = distinct !DISubprogram(name: "foo", scope: [[META1]], file: [[META1]], line: 8, type: [[META5:![0-9]+]], scopeLine: 8, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: [[META0]], retainedNodes: [[META9:![0-9]+]])
+; CHECK: [[META5]] = !DISubroutineType(types: [[META6:![0-9]+]])
+; CHECK: [[META6]] = !{null, [[META7:![0-9]+]]}
+; CHECK: [[META7]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: [[META8:![0-9]+]], size: 64)
+; CHECK: [[META8]] = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+; CHECK: [[META9]] = !{[[META10:![0-9]+]], [[META11]], [[META14:![0-9]+]], [[META17:![0-9]+]]}
+; CHECK: [[META10]] = !DILocalVariable(name: "h", arg: 1, scope: [[DBG4]], file: [[META1]], line: 8, type: [[META7]])
+; CHECK: [[META11]] = !DILocalVariable(name: "i", scope: [[META12:![0-9]+]], file: [[META1]], line: 10, type: [[META13:![0-9]+]])
+; CHECK: [[META12]] = distinct !DILexicalBlock(scope: [[DBG4]], file: [[META1]], line: 10, column: 3)
+; CHECK: [[META13]] = !DIBasicType(name: "unsigned long", size: 64, encoding: DW_ATE_unsigned)
+; CHECK: [[META14]] = !DILocalVariable(name: "l", scope: [[META15:![0-9]+]], file: [[META1]], line: 11, type: [[META13]])
+; CHECK: [[META15]] = distinct !DILexicalBlock(scope: [[META16:![0-9]+]], file: [[META1]], line: 11, column: 5)
+; CHECK: [[META16]] = distinct !DILexicalBlock(scope: [[META12]], file: [[META1]], line: 10, column: 3)
+; CHECK: [[META17]] = !DILocalVariable(name: "j", scope: [[META18:![0-9]+]], file: [[META1]], line: 12, type: [[META13]])
+; CHECK: [[META18]] = distinct !DILexicalBlock(scope: [[META19:![0-9]+]], file: [[META1]], line: 12, column: 7)
+; CHECK: [[META19]] = distinct !DILexicalBlock(scope: [[META15]], file: [[META1]], line: 11, column: 5)
+; CHECK: [[DBG20]] = !DILocation(line: 0, scope: [[META12]])
+; CHECK: [[DBG21]] = !DILocation(line: 10, column: 3, scope: [[META12]])
+; CHECK: [[DBG22]] = !DILocation(line: 13, column: 11, scope: [[META23:![0-9]+]])
+; CHECK: [[META23]] = distinct !DILexicalBlock(scope: [[META18]], file: [[META1]], line: 12, column: 7)
+; CHECK: [[DBG24]] = !DILocation(line: 11, column: 32, scope: [[META19]])
+; CHECK: [[DBG25]] = !DILocation(line: 11, column: 26, scope: [[META19]])
+; CHECK: [[DBG26]] = !DILocation(line: 10, column: 30, scope: [[META16]])
+; CHECK: [[DBG27]] = !DILocation(line: 10, column: 24, scope: [[META16]])
+; CHECK: [[LOOP28]] = distinct !{[[LOOP28]], [[DBG21]], [[META29:![0-9]+]], [[META30:![0-9]+]], [[META31:![0-9]+]]}
+; CHECK: [[META29]] = !DILocation(line: 13, column: 13, scope: [[META12]])
+; CHECK: [[META30]] = !{!"llvm.loop.isvectorized", i32 1}
+; CHECK: [[META31]] = !{!"llvm.loop.unroll.runtime.disable"}
+; CHECK: [[DBG32]] = !DILocation(line: 11, column: 5, scope: [[META15]])
+; CHECK: [[DBG33]] = !DILocation(line: 13, column: 2, scope: [[META23]])
+; CHECK: [[LOOP34]] = distinct !{[[LOOP34]], [[DBG21]], [[META29]], [[META30]]}
+; CHECK: [[DBG35]] = !DILocation(line: 14, column: 1, scope: [[DBG4]])
+;.


        


More information about the llvm-commits mailing list