<div dir="ltr">Does this cause changes in non-debug IR in the presence of debug info intrinsics? (you mention that "<span style="font-family:monospace">If there were uses of values produced by these instructions that were outside the loop, we have to insert PHI nodes to merge the two values." - that sounds like it could be a problem, as enabling debug info is not intended to change optimization/code generation)</span></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 26, 2016 at 3:34 PM, Thomas Jablin via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">tjablin created this revision.<br>
tjablin added reviewers: kbarton, hfinkel, cycheng.<br>
tjablin added a subscriber: llvm-commits.<br>
Herald added a subscriber: mzolotukhin.<br>
<br>
Loop rotation clones instruction from the old header into the preheader. If there were uses of values produced by these instructions that were outside the loop, we have to insert PHI nodes to merge the two values. If the values are used by DbgIntrinsics they will be used as a MetadataAsValue of a ValueAsMetadata of the original values, and iterating all of the uses of the original value will not update the DbgIntrinsics. The new code checks if the values are used by DbgIntrinsics and if so, updates them using essentially the same logic as the original code.<br>
<br>
The attached testcase demonstrates the issue. Without the fix, the DbgIntrinic outside the loop uses values computed inside the loop, even though these values do not dominate the DbgIntrinsic.<br>
<br>
<a href="http://reviews.llvm.org/D19564" rel="noreferrer" target="_blank">http://reviews.llvm.org/D19564</a><br>
<br>
Files:<br>
lib/Transforms/Scalar/LoopRotation.cpp<br>
test/Transforms/LoopRotate/dbgvalue.ll<br>
<br>
Index: test/Transforms/LoopRotate/dbgvalue.ll<br>
===================================================================<br>
--- test/Transforms/LoopRotate/dbgvalue.ll<br>
+++ test/Transforms/LoopRotate/dbgvalue.ll<br>
@@ -7,6 +7,7 @@<br>
; CHECK-LABEL: define i32 @tak(<br>
; CHECK: entry<br>
; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 %x<br>
+; CHECK: tail call void @llvm.dbg.value(metadata i32 %call<br>
<br>
entry:<br>
br label %tailrecurse<br>
@@ -37,6 +38,44 @@<br>
ret i32 %<a href="http://z.tr" rel="noreferrer" target="_blank">z.tr</a>, !dbg !17<br>
}<br>
<br>
+define i32 @tak2(i32 %x, i32 %y, i32 %z) nounwind ssp !dbg !0 {<br>
+; CHECK-LABEL: define i32 @tak2(<br>
+; CHECK: entry<br>
+; CHECK: tail call void @llvm.dbg.value(metadata i32 %<a href="http://x.tr" rel="noreferrer" target="_blank">x.tr</a><br>
+; CHECK: tail call void @llvm.dbg.value(metadata i32 %<a href="http://x.tr" rel="noreferrer" target="_blank">x.tr</a><br>
+<br>
+entry:<br>
+ br label %tailrecurse<br>
+<br>
+tailrecurse: ; preds = %if.then, %entry<br>
+ %<a href="http://x.tr" rel="noreferrer" target="_blank">x.tr</a> = phi i32 [ %x, %entry ], [ %call, %if.then ]<br>
+ %<a href="http://y.tr" rel="noreferrer" target="_blank">y.tr</a> = phi i32 [ %y, %entry ], [ %call9, %if.then ]<br>
+ %<a href="http://z.tr" rel="noreferrer" target="_blank">z.tr</a> = phi i32 [ %z, %entry ], [ %call14, %if.then ]<br>
+ %cmp = icmp slt i32 %<a href="http://y.tr" rel="noreferrer" target="_blank">y.tr</a>, %<a href="http://x.tr" rel="noreferrer" target="_blank">x.tr</a>, !dbg !12<br>
+ br i1 %cmp, label %if.then, label %if.end, !dbg !12<br>
+<br>
+if.then: ; preds = %tailrecurse<br>
+ tail call void @llvm.dbg.value(metadata i32 %<a href="http://x.tr" rel="noreferrer" target="_blank">x.tr</a>, i64 0, metadata !6, metadata !DIExpression()), !dbg !7<br>
+ tail call void @llvm.dbg.value(metadata i32 %<a href="http://y.tr" rel="noreferrer" target="_blank">y.tr</a>, i64 0, metadata !8, metadata !DIExpression()), !dbg !9<br>
+ tail call void @llvm.dbg.value(metadata i32 %<a href="http://z.tr" rel="noreferrer" target="_blank">z.tr</a>, i64 0, metadata !10, metadata !DIExpression()), !dbg !11<br>
+ %sub = sub nsw i32 %<a href="http://x.tr" rel="noreferrer" target="_blank">x.tr</a>, 1, !dbg !14<br>
+ %call = tail call i32 @tak(i32 %sub, i32 %<a href="http://y.tr" rel="noreferrer" target="_blank">y.tr</a>, i32 %<a href="http://z.tr" rel="noreferrer" target="_blank">z.tr</a>), !dbg !14<br>
+ %sub6 = sub nsw i32 %<a href="http://y.tr" rel="noreferrer" target="_blank">y.tr</a>, 1, !dbg !14<br>
+ %call9 = tail call i32 @tak(i32 %sub6, i32 %<a href="http://z.tr" rel="noreferrer" target="_blank">z.tr</a>, i32 %<a href="http://x.tr" rel="noreferrer" target="_blank">x.tr</a>), !dbg !14<br>
+ %sub11 = sub nsw i32 %<a href="http://z.tr" rel="noreferrer" target="_blank">z.tr</a>, 1, !dbg !14<br>
+ %call14 = tail call i32 @tak(i32 %sub11, i32 %<a href="http://x.tr" rel="noreferrer" target="_blank">x.tr</a>, i32 %<a href="http://y.tr" rel="noreferrer" target="_blank">y.tr</a>), !dbg !14<br>
+ br label %tailrecurse<br>
+<br>
+if.end: ; preds = %tailrecurse<br>
+ tail call void @llvm.dbg.value(metadata i32 %<a href="http://x.tr" rel="noreferrer" target="_blank">x.tr</a>, i64 0, metadata !6, metadata !DIExpression()), !dbg !7<br>
+ tail call void @llvm.dbg.value(metadata i32 %<a href="http://y.tr" rel="noreferrer" target="_blank">y.tr</a>, i64 0, metadata !8, metadata !DIExpression()), !dbg !9<br>
+ tail call void @llvm.dbg.value(metadata i32 %<a href="http://z.tr" rel="noreferrer" target="_blank">z.tr</a>, i64 0, metadata !10, metadata !DIExpression()), !dbg !11<br>
+ br label %return, !dbg !16<br>
+<br>
+return: ; preds = %if.end<br>
+ ret i32 %<a href="http://z.tr" rel="noreferrer" target="_blank">z.tr</a>, !dbg !17<br>
+}<br>
+<br>
@channelColumns = external global i64<br>
@horzPlane = external global i8*, align 8<br>
<br>
Index: lib/Transforms/Scalar/LoopRotation.cpp<br>
===================================================================<br>
--- lib/Transforms/Scalar/LoopRotation.cpp<br>
+++ lib/Transforms/Scalar/LoopRotation.cpp<br>
@@ -108,6 +108,33 @@<br>
<br>
// Anything else can be handled by SSAUpdater.<br>
SSA.RewriteUse(U);<br>
+<br>
+ // Replace MetadataAsValue(ValueAsMetadata(OrigHeaderVal)) uses in debug<br>
+ // intrinsics<br>
+ LLVMContext &C = OrigHeader->getContext();<br>
+ if (ValueAsMetadata *VAM = ValueAsMetadata::getIfExists(OrigHeaderVal)) {<br>
+ if (MetadataAsValue *MAV = MetadataAsValue::getIfExists(C, VAM)) {<br>
+ for (auto UI = MAV->use_begin(), E = MAV->use_end(); UI != E; ) {<br>
+ // Grab the use before incrementing the iterator.<br>
+ Use &U = *UI++;<br>
+ DbgInfoIntrinsic *UserInst = cast<DbgInfoIntrinsic>(U.getUser());<br>
+ BasicBlock *UserBB = UserInst->getParent();<br>
+<br>
+ // The original users in the OrigHeader are already using the<br>
+ // original definitions.<br>
+ if (UserBB == OrigHeader)<br>
+ continue;<br>
+<br>
+ // Users in the OrigPreHeader need to use the value to which the<br>
+ // original definitions are mapped and anything else can be handled<br>
+ // by the SSAUpdater<br>
+ Value *NewVal = UserBB == OrigPreheader ?<br>
+ OrigPreHeaderVal :<br>
+ SSA.GetValueInMiddleOfBlock(UserBB);<br>
+ U = MetadataAsValue::get(C, ValueAsMetadata::get(NewVal));<br>
+ }<br>
+ }<br>
+ }<br>
}<br>
}<br>
}<br>
<br>
<br>
<br>_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
<br></blockquote></div><br></div>