[llvm] [DebugInfo][RemoveDIs] Instrument loop-rotate for DPValues (PR #72997)
Orlando Cazalet-Hyams via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 21 14:50:30 PST 2023
================
@@ -38,12 +61,81 @@ return: ; preds = %if.end
ret i32 %z.tr, !dbg !17
}
-define i32 @tak2(i32 %x, i32 %y, i32 %z) nounwind ssp !dbg !21 {
-; CHECK-LABEL: define i32 @tak2(
+; Repeat of the tak function, with only one DILocalVariable, checking that we
+; don't insert duplicate debug intrinsics. The initial duplicates are preserved.
+; FIXME: this test checks for the de-duplication behaviour that loop-rotate
+; has today, however it might not be correct -- should not the _last_
+; assignment to the variable be preserved, not the first?
+define i32 @tak_dup(i32 %x, i32 %y, i32 %z) nounwind ssp !dbg !50 {
+; CHECK-LABEL: define i32 @tak_dup(
; CHECK: entry
-; CHECK: tail call void @llvm.dbg.value(metadata i32 %x.tr
-; CHECK: tail call void @llvm.dbg.value(metadata i32 undef
+; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 %x
+; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 %y
+; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 %z
+; CHECK: if.then.lr.ph:
+; CHECK: if.then:
+; CHECK-NEXT: %z.tr4 = phi
+; CHECK-NEXT: %y.tr3 = phi
+; CHECK-NEXT: %x.tr2 = phi
+; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 %x.tr2
+; CHECK: %call = tail call i32 @tak(i32
+; CHECK: %call9 = tail call i32 @tak(i32
+; CHECK: %call14 = tail call i32 @tak(i32
+; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 %call14
+entry:
+ br label %tailrecurse
+tailrecurse: ; preds = %if.then, %entry
+ %x.tr = phi i32 [ %x, %entry ], [ %call, %if.then ]
+ %y.tr = phi i32 [ %y, %entry ], [ %call9, %if.then ]
+ %z.tr = phi i32 [ %z, %entry ], [ %call14, %if.then ]
+ tail call void @llvm.dbg.value(metadata i32 %x.tr, metadata !60, metadata !DIExpression()), !dbg !61
+ tail call void @llvm.dbg.value(metadata i32 %y.tr, metadata !60, metadata !DIExpression()), !dbg !61
+ tail call void @llvm.dbg.value(metadata i32 %z.tr, metadata !60, metadata !DIExpression()), !dbg !61
+ %cmp = icmp slt i32 %y.tr, %x.tr, !dbg !62
+ br i1 %cmp, label %if.then, label %if.end, !dbg !62
+
+if.then: ; preds = %tailrecurse
+ %sub = sub nsw i32 %x.tr, 1, !dbg !64
+ %call = tail call i32 @tak(i32 %sub, i32 %y.tr, i32 %z.tr), !dbg !64
+ %sub6 = sub nsw i32 %y.tr, 1, !dbg !64
+ %call9 = tail call i32 @tak(i32 %sub6, i32 %z.tr, i32 %x.tr), !dbg !64
+ %sub11 = sub nsw i32 %z.tr, 1, !dbg !64
+ %call14 = tail call i32 @tak(i32 %sub11, i32 %x.tr, i32 %y.tr), !dbg !64
+ br label %tailrecurse
+
+if.end: ; preds = %tailrecurse
+ br label %return, !dbg !66
+
+return: ; preds = %if.end
+ ret i32 %z.tr, !dbg !67
+}
+
+; Check that the dbg.values move up to being immediately below the PHIs,
+; using their Values. However once we exit the loop, the x and y values
+; become irrelevant and undef, only z gets an LCSSA PHI to preserve it.
+; FIXME: could we do better than this?
+; (The icmp is initially undominated by any dbg.value, but as the first
+; iteration is peeled off into the entry block, it's then safe to have it
+; dominated by subsequent dbg.values).
----------------
OCHyams wrote:
> dominated by subsequent dbg.values
postdominated? or does "subsequent" refer to position prior to rotation?
(alternatively: these questions might make no sense, I'm not 100% sure I understand what you're saying in the braces above)
https://github.com/llvm/llvm-project/pull/72997
More information about the llvm-commits
mailing list