[llvm] [DebugInfo][LoopDistribute] Salvage debug values using dead instructions in the distributed loops (PR #137124)

Orlando Cazalet-Hyams via llvm-commits llvm-commits at lists.llvm.org
Tue May 6 05:19:24 PDT 2025


================
@@ -0,0 +1,100 @@
+; RUN: opt -passes=loop-distribute -enable-loop-distribute -S < %s  | FileCheck %s
+
+; Check that removeUnusedInsts() salvages `dbg_value`s which use dead
+; instructions in the distributed loops.
+
+define void @f(ptr noalias %a, ptr noalias %c, ptr noalias %d) !dbg !5 {
+; CHECK-LABEL: define void @f(
+; CHECK-SAME: ptr noalias [[A:%.*]], ptr noalias [[C:%.*]], ptr noalias [[D:%.*]])
+
+entry:
+  br label %for.body, !dbg !21
+
+for.body:                                         ; preds = %for.body, %entry
+  %ind = phi i64 [ 0, %entry ], [ %add, %for.body ], !dbg !22
+  #dbg_value(i64 %ind, !9, !DIExpression(), !22)
+  %add = add nuw nsw i64 %ind, 1, !dbg !23
+  #dbg_value(i64 %add, !11, !DIExpression(), !23)
+
+
+; CHECK-LABEL: for.body.ldist1:
+; CHECK: #dbg_value(!DIArgList(ptr [[D]], i64 [[IND_LDIST1:%.*]]), [[META16:![0-9]+]], !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_constu, 4, DW_OP_mul, DW_OP_plus, DW_OP_stack_value), [[META28:![0-9]+]])
+; CHECK: #dbg_value(!DIArgList(ptr [[C]], i64 [[IND_LDIST1]]), [[META18:![0-9]+]], !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_constu, 4, DW_OP_mul, DW_OP_plus, DW_OP_stack_value), [[META30:![0-9]+]])
+;
+  %arrayidxA = getelementptr inbounds i32, ptr %a, i64 %ind, !dbg !24
+  #dbg_value(ptr %arrayidxA, !12, !DIExpression(), !24)
+  %loadA = load i32, ptr %arrayidxA, align 4, !dbg !25
+  #dbg_value(i32 %loadA, !13, !DIExpression(), !25)
+  %arrayidxA_plus_4 = getelementptr inbounds i32, ptr %a, i64 %add, !dbg !26
+  #dbg_value(ptr %arrayidxA_plus_4, !15, !DIExpression(), !26)
+  store i32 %loadA, ptr %arrayidxA_plus_4, align 4, !dbg !27
+
+; CHECK-LABEL: for.body:
+; CHECK: #dbg_value(!DIArgList(ptr [[A]], i64 [[IND:%.*]]), [[META12:![0-9]+]], !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_constu, 4, DW_OP_mul, DW_OP_plus, DW_OP_stack_value), [[DBG24:![0-9]+]])
+; CHECK: #dbg_value(!DIArgList(ptr [[A]], i64 [[ADD:%.*]]), [[META15:![0-9]+]], !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_constu, 4, DW_OP_mul, DW_OP_plus, DW_OP_stack_value), [[DBG26:![0-9]+]])
+;
+  %arrayidxD = getelementptr inbounds i32, ptr %d, i64 %ind, !dbg !28
+  #dbg_value(ptr %arrayidxD, !16, !DIExpression(), !28)
+  %loadD = load i32, ptr %arrayidxD, align 4, !dbg !29
+  #dbg_value(i32 %loadD, !17, !DIExpression(), !29)
+  %arrayidxC = getelementptr inbounds i32, ptr %c, i64 %ind, !dbg !30
+  #dbg_value(ptr %arrayidxC, !18, !DIExpression(), !30)
+  store i32 %loadD, ptr %arrayidxC, align 4, !dbg !31
+
+  %exitcond = icmp eq i64 %add, 20, !dbg !32
+  #dbg_value(i1 %exitcond, !19, !DIExpression(), !32)
----------------
OCHyams wrote:

Do we need all the dbg_values? I feel like we probably get the same coverage (and a simpler test) if there's just one `dbg_value`?

nit: please can you indent the dbg_values by two spaces? that's how LLVM prints them, and it's easier to read that way.

https://github.com/llvm/llvm-project/pull/137124


More information about the llvm-commits mailing list