Index: llvm/lib/Transforms/Utils/LCSSA.cpp =================================================================== --- llvm/lib/Transforms/Utils/LCSSA.cpp +++ llvm/lib/Transforms/Utils/LCSSA.cpp @@ -265,15 +265,11 @@ Worklist.push_back(PostProcessPN); // Keep track of PHI nodes that we want to remove because they did not have - // any uses rewritten. If the new PHI is used, store it so that we can - // try to propagate dbg.value intrinsics to it. - SmallVector NeedDbgValues; + // any uses rewritten. for (PHINode *PN : AddedPHIs) if (PN->use_empty()) LocalPHIsToRemove.insert(PN); - else - NeedDbgValues.push_back(PN); - insertDebugValuesForPHIs(InstBB, NeedDbgValues); + Changed = true; } Index: llvm/test/Transforms/LCSSA/DontInsertDebugValuesForPHIs.ll =================================================================== --- /dev/null +++ llvm/test/Transforms/LCSSA/DontInsertDebugValuesForPHIs.ll @@ -0,0 +1,57 @@ +; RUN: opt < %s -lcssa -S | FileCheck %s + +; This test ensures that LCSSA does not insert dbg.value intrinsics using +; insertDebugValuesForPHIs() which effectively cause assignments to be +; re-ordered. +; See PR48206 for more information. + +define dso_local i32 @_Z5lcssab(i1 zeroext %S2) { +entry: + br label %loop.interior + +loop.interior: ; preds = %post.if, %entry + br i1 %S2, label %if.true, label %if.false + +if.true: ; preds = %loop.interior + %X1 = add i32 0, 0 + br label %post.if + +if.false: ; preds = %loop.interior + %X2 = add i32 0, 1 + br label %post.if + +post.if: ; preds = %if.false, %if.true + %X3 = phi i32 [ %X1, %if.true ], [ %X2, %if.false ], !dbg !21 + call void @llvm.dbg.value(metadata i32 %X3, metadata !9, metadata !DIExpression()), !dbg !21 + %Y1 = add i32 4, %X3, !dbg !22 + call void @llvm.dbg.value(metadata i32 %Y1, metadata !9, metadata !DIExpression()), !dbg !22 + br i1 %S2, label %loop.exit, label %loop.interior, !dbg !23 + +loop.exit: ; preds = %post.if +; CHECK: loop.exit: +; CHECK-NEXT: %X3.lcssa = phi i32 +; CHECK-NOT: call void @llvm.dbg.value + %X4 = add i32 3, %X3 + ret i32 %X4 +} + +declare void @llvm.dbg.value(metadata, metadata, metadata) + +!llvm.dbg.cu = !{!0} +!llvm.debugify = !{!3, !4} +!llvm.module.flags = !{!5} + +!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify and Author", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2) +!1 = !DIFile(filename: "./testcase.ll", directory: "/") +!2 = !{} +!3 = !{i32 11} +!4 = !{i32 5} +!5 = !{i32 2, !"Debug Info Version", i32 3} +!6 = distinct !DISubprogram(name: "_Z5lcssab", linkageName: "_Z5lcssab", scope: null, file: !1, line: 1, type: !7, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !{!9}) +!7 = !DISubroutineType(types: !2) +!9 = !DILocalVariable(name: "var", scope: !6, file: !1, line: 3, type: !10) +!10 = !DIBasicType(name: "ty32", size: 32, encoding: DW_ATE_unsigned) +!21 = !DILocation(line: 7, column: 1, scope: !6) +!22 = !DILocation(line: 8, column: 1, scope: !6) +!23 = !DILocation(line: 9, column: 1, scope: !6) + Index: llvm/test/Transforms/LCSSA/basictest.ll =================================================================== --- llvm/test/Transforms/LCSSA/basictest.ll +++ llvm/test/Transforms/LCSSA/basictest.ll @@ -20,7 +20,6 @@ loop.exit: ; preds = %post.if ; CHECK: %X3.lcssa = phi i32 ; DEBUGIFY: %X3.lcssa = phi i32 {{.*}}, !dbg ![[DbgLoc:[0-9]+]] -; DEBUGIFY-NEXT: call void @llvm.dbg.value(metadata i32 %X3.lcssa ; CHECK: %X4 = add i32 3, %X3.lcssa %X4 = add i32 3, %X3 ; [#uses=0] ret void Index: llvm/test/Transforms/LoopIdiom/X86/left-shift-until-bittest.ll =================================================================== --- llvm/test/Transforms/LoopIdiom/X86/left-shift-until-bittest.ll +++ llvm/test/Transforms/LoopIdiom/X86/left-shift-until-bittest.ll @@ -32,7 +32,6 @@ ; ALL-NEXT: br i1 [[X_CURR_ISBITUNSET]], label [[LOOP]], label [[END:%.*]], [[DBG22:!dbg !.*]] ; ALL: end: ; ALL-NEXT: [[X_CURR_LCSSA:%.*]] = phi i32 [ [[X_CURR]], [[LOOP]] ], [[DBG18]] -; ALL-NEXT: call void @llvm.dbg.value(metadata i32 [[X_CURR_LCSSA]], [[META11]], metadata !DIExpression()), [[DBG18]] ; ALL-NEXT: ret i32 [[X_CURR_LCSSA]], [[DBG23:!dbg !.*]] ; entry: @@ -69,7 +68,6 @@ ; ALL-NEXT: br i1 [[X_CURR_ISBITUNSET]], label [[LOOP]], label [[END:%.*]], [[DBG38:!dbg !.*]] ; ALL: end: ; ALL-NEXT: [[X_CURR_LCSSA:%.*]] = phi i16 [ [[X_CURR]], [[LOOP]] ], [[DBG34]] -; ALL-NEXT: call void @llvm.dbg.value(metadata i16 [[X_CURR_LCSSA]], [[META28]], metadata !DIExpression()), [[DBG34]] ; ALL-NEXT: ret i16 [[X_CURR_LCSSA]], [[DBG39:!dbg !.*]] ; entry: @@ -103,7 +101,6 @@ ; ALL-NEXT: br i1 [[X_CURR_ISBITUNSET]], label [[LOOP]], label [[END:%.*]], [[DBG51:!dbg !.*]] ; ALL: end: ; ALL-NEXT: [[X_CURR_LCSSA:%.*]] = phi i32 [ [[X_CURR]], [[LOOP]] ], [[DBG47]] -; ALL-NEXT: call void @llvm.dbg.value(metadata i32 [[X_CURR_LCSSA]], [[META42]], metadata !DIExpression()), [[DBG47]] ; ALL-NEXT: ret i32 [[X_CURR_LCSSA]], [[DBG52:!dbg !.*]] ; entry: @@ -136,7 +133,6 @@ ; ALL-NEXT: br i1 [[X_CURR_ISBITUNSET]], label [[LOOP]], label [[END:%.*]], [[DBG64:!dbg !.*]] ; ALL: end: ; ALL-NEXT: [[X_CURR_LCSSA:%.*]] = phi i32 [ [[X_CURR]], [[LOOP]] ], [[DBG60]] -; ALL-NEXT: call void @llvm.dbg.value(metadata i32 [[X_CURR_LCSSA]], [[META55]], metadata !DIExpression()), [[DBG60]] ; ALL-NEXT: ret i32 [[X_CURR_LCSSA]], [[DBG65:!dbg !.*]] ; entry: @@ -169,7 +165,6 @@ ; ALL-NEXT: br i1 [[X_CURR_ISBITUNSET]], label [[LOOP]], label [[END:%.*]], [[DBG77:!dbg !.*]] ; ALL: end: ; ALL-NEXT: [[X_CURR_LCSSA:%.*]] = phi i32 [ [[X_CURR]], [[LOOP]] ], [[DBG73]] -; ALL-NEXT: call void @llvm.dbg.value(metadata i32 [[X_CURR_LCSSA]], [[META68]], metadata !DIExpression()), [[DBG73]] ; ALL-NEXT: ret i32 [[X_CURR_LCSSA]], [[DBG78:!dbg !.*]] ; entry: @@ -200,7 +195,6 @@ ; ALL-NEXT: br i1 [[X_CURR_ISBITUNSET]], label [[LOOP]], label [[END:%.*]], [[DBG88:!dbg !.*]] ; ALL: end: ; ALL-NEXT: [[X_CURR_LCSSA:%.*]] = phi i32 [ [[X_CURR]], [[LOOP]] ], [[DBG85]] -; ALL-NEXT: call void @llvm.dbg.value(metadata i32 [[X_CURR_LCSSA]], [[META81]], metadata !DIExpression()), [[DBG85]] ; ALL-NEXT: ret i32 [[X_CURR_LCSSA]], [[DBG89:!dbg !.*]] ; entry: @@ -235,7 +229,6 @@ ; ALL-NEXT: br i1 [[X_CURR_ISBITUNSET]], label [[END:%.*]], label [[LOOP]], [[DBG103:!dbg !.*]] ; ALL: end: ; ALL-NEXT: [[X_CURR_LCSSA:%.*]] = phi i32 [ [[X_CURR]], [[LOOP]] ], [[DBG99]] -; ALL-NEXT: call void @llvm.dbg.value(metadata i32 [[X_CURR_LCSSA]], [[META93]], metadata !DIExpression()), [[DBG99]] ; ALL-NEXT: ret i32 [[X_CURR_LCSSA]], [[DBG104:!dbg !.*]] ; entry: @@ -272,7 +265,6 @@ ; ALL-NEXT: br i1 [[X_CURR_ISBITUNSET]], label [[LOOP]], label [[END:%.*]], [[DBG118:!dbg !.*]] ; ALL: end: ; ALL-NEXT: [[X_CURR_LCSSA:%.*]] = phi i32 [ [[X_CURR]], [[LOOP]] ], [[DBG114]] -; ALL-NEXT: call void @llvm.dbg.value(metadata i32 [[X_CURR_LCSSA]], [[META108]], metadata !DIExpression()), [[DBG114]] ; ALL-NEXT: ret i32 [[X_CURR_LCSSA]], [[DBG119:!dbg !.*]] ; entry: @@ -310,7 +302,6 @@ ; ALL-NEXT: br i1 [[X_CURR_ISBITUNSET]], label [[LOOP]], label [[END:%.*]], [[DBG133:!dbg !.*]] ; ALL: end: ; ALL-NEXT: [[X_CURR_LCSSA:%.*]] = phi i32 [ [[X_CURR]], [[LOOP]] ], [[DBG129]] -; ALL-NEXT: call void @llvm.dbg.value(metadata i32 [[X_CURR_LCSSA]], [[META123]], metadata !DIExpression()), [[DBG129]] ; ALL-NEXT: ret i32 [[X_CURR_LCSSA]], [[DBG134:!dbg !.*]] ; entry: @@ -343,7 +334,6 @@ ; ALL-NEXT: br i1 [[X_CURR_ISBITUNSET]], label [[END:%.*]], label [[LOOP]], [[DBG144:!dbg !.*]] ; ALL: end: ; ALL-NEXT: [[X_CURR_LCSSA:%.*]] = phi i32 [ [[X_CURR]], [[LOOP]] ], [[DBG141]] -; ALL-NEXT: call void @llvm.dbg.value(metadata i32 [[X_CURR_LCSSA]], [[META137]], metadata !DIExpression()), [[DBG141]] ; ALL-NEXT: ret i32 [[X_CURR_LCSSA]], [[DBG145:!dbg !.*]] ; entry: @@ -381,7 +371,6 @@ ; ALL-NEXT: br i1 [[X_CURR_ISBITUNSET]], label [[LOOP]], label [[END:%.*]], [[DBG159:!dbg !.*]] ; ALL: end: ; ALL-NEXT: [[X_CURR_LCSSA:%.*]] = phi i32 [ [[X_CURR]], [[LOOP]] ], [[DBG154]] -; ALL-NEXT: call void @llvm.dbg.value(metadata i32 [[X_CURR_LCSSA]], [[META148]], metadata !DIExpression()), [[DBG154]] ; ALL-NEXT: ret i32 [[X_CURR_LCSSA]], [[DBG160:!dbg !.*]] ; entry: @@ -418,7 +407,6 @@ ; ALL-NEXT: br i1 [[X_CURR_ISBITUNSET]], label [[LOOP]], label [[END:%.*]], [[DBG174:!dbg !.*]] ; ALL: end: ; ALL-NEXT: [[X_CURR_LCSSA:%.*]] = phi i32 [ [[X_CURR]], [[LOOP]] ], [[DBG169]] -; ALL-NEXT: call void @llvm.dbg.value(metadata i32 [[X_CURR_LCSSA]], [[META163]], metadata !DIExpression()), [[DBG169]] ; ALL-NEXT: ret i32 [[X_CURR_LCSSA]], [[DBG175:!dbg !.*]] ; entry: @@ -455,7 +443,6 @@ ; ALL-NEXT: br i1 [[X_CURR_ISBITUNSET]], label [[LOOP]], label [[END:%.*]], [[DBG189:!dbg !.*]] ; ALL: end: ; ALL-NEXT: [[X_CURR_LCSSA:%.*]] = phi i32 [ [[X_CURR]], [[LOOP]] ], [[DBG185]] -; ALL-NEXT: call void @llvm.dbg.value(metadata i32 [[X_CURR_LCSSA]], [[META179]], metadata !DIExpression()), [[DBG185]] ; ALL-NEXT: ret i32 [[X_CURR_LCSSA]], [[DBG190:!dbg !.*]] ; entry: @@ -492,7 +479,6 @@ ; ALL-NEXT: br i1 [[X_CURR_ISBITUNSET]], label [[LOOP]], label [[END:%.*]], [[DBG204:!dbg !.*]] ; ALL: end: ; ALL-NEXT: [[X_CURR_LCSSA:%.*]] = phi i32 [ [[X_CURR]], [[LOOP]] ], [[DBG200]] -; ALL-NEXT: call void @llvm.dbg.value(metadata i32 [[X_CURR_LCSSA]], [[META194]], metadata !DIExpression()), [[DBG200]] ; ALL-NEXT: ret i32 [[X_CURR_LCSSA]], [[DBG205:!dbg !.*]] ; entry: @@ -529,7 +515,6 @@ ; ALL-NEXT: br i1 [[X_CURR_ISBITUNSET]], label [[LOOP]], label [[END:%.*]], [[DBG219:!dbg !.*]] ; ALL: end: ; ALL-NEXT: [[X_CURR_LCSSA:%.*]] = phi i32 [ [[X_CURR]], [[LOOP]] ], [[DBG215]] -; ALL-NEXT: call void @llvm.dbg.value(metadata i32 [[X_CURR_LCSSA]], [[META209]], metadata !DIExpression()), [[DBG215]] ; ALL-NEXT: ret i32 [[X_CURR_LCSSA]], [[DBG220:!dbg !.*]] ; entry: @@ -566,7 +551,6 @@ ; ALL-NEXT: br i1 [[X_CURR_ISBITUNSET]], label [[END:%.*]], label [[LOOP]], [[DBG234:!dbg !.*]] ; ALL: end: ; ALL-NEXT: [[X_CURR_LCSSA:%.*]] = phi i32 [ [[X_CURR]], [[LOOP]] ], [[DBG230]] -; ALL-NEXT: call void @llvm.dbg.value(metadata i32 [[X_CURR_LCSSA]], [[META224]], metadata !DIExpression()), [[DBG230]] ; ALL-NEXT: ret i32 [[X_CURR_LCSSA]], [[DBG235:!dbg !.*]] ; entry: @@ -603,7 +587,6 @@ ; ALL-NEXT: br i1 [[X_CURR_ISBITUNSET]], label [[LOOP]], label [[END:%.*]], [[DBG249:!dbg !.*]] ; ALL: end: ; ALL-NEXT: [[X_CURR_LCSSA:%.*]] = phi i32 [ [[X_CURR]], [[LOOP]] ], [[DBG245]] -; ALL-NEXT: call void @llvm.dbg.value(metadata i32 [[X_CURR_LCSSA]], [[META239]], metadata !DIExpression()), [[DBG245]] ; ALL-NEXT: ret i32 [[X_CURR_LCSSA]], [[DBG250:!dbg !.*]] ; entry: @@ -674,7 +657,6 @@ ; ALL-NEXT: br i1 [[X_CURR_ISBITUNSET]], label [[LOOP]], label [[END:%.*]], [[DBG279:!dbg !.*]] ; ALL: end: ; ALL-NEXT: [[X_CURR_LCSSA:%.*]] = phi i32 [ [[X_CURR]], [[LOOP]] ], [[DBG275]] -; ALL-NEXT: call void @llvm.dbg.value(metadata i32 [[X_CURR_LCSSA]], [[META269]], metadata !DIExpression()), [[DBG275]] ; ALL-NEXT: ret i32 [[X_CURR_LCSSA]], [[DBG280:!dbg !.*]] ; entry: @@ -711,7 +693,6 @@ ; ALL-NEXT: br i1 [[X_CURR_ISBITUNSET]], label [[LOOP]], label [[END:%.*]], [[DBG294:!dbg !.*]] ; ALL: end: ; ALL-NEXT: [[X_CURR_LCSSA:%.*]] = phi i32 [ [[X_CURR]], [[LOOP]] ], [[DBG290]] -; ALL-NEXT: call void @llvm.dbg.value(metadata i32 [[X_CURR_LCSSA]], [[META284]], metadata !DIExpression()), [[DBG290]] ; ALL-NEXT: ret i32 [[X_CURR_LCSSA]], [[DBG295:!dbg !.*]] ; entry: @@ -748,7 +729,6 @@ ; ALL-NEXT: br i1 [[X_CURR_ISBITUNSET]], label [[LOOP]], label [[END:%.*]], [[DBG309:!dbg !.*]] ; ALL: end: ; ALL-NEXT: [[X_CURR_LCSSA:%.*]] = phi i32 [ [[X_CURR]], [[LOOP]] ], [[DBG305]] -; ALL-NEXT: call void @llvm.dbg.value(metadata i32 [[X_CURR_LCSSA]], [[META299]], metadata !DIExpression()), [[DBG305]] ; ALL-NEXT: ret i32 [[X_CURR_LCSSA]], [[DBG310:!dbg !.*]] ; entry: @@ -783,7 +763,6 @@ ; ALL-NEXT: br i1 [[X_CURR_ISBITUNSET]], label [[LOOP]], label [[END:%.*]], [[DBG322:!dbg !.*]] ; ALL: end: ; ALL-NEXT: [[X_CURR_LCSSA:%.*]] = phi i32 [ [[X_CURR]], [[LOOP]] ], [[DBG318]] -; ALL-NEXT: call void @llvm.dbg.value(metadata i32 [[X_CURR_LCSSA]], [[META313]], metadata !DIExpression()), [[DBG318]] ; ALL-NEXT: ret i32 [[X_CURR_LCSSA]], [[DBG323:!dbg !.*]] ; entry: @@ -817,7 +796,6 @@ ; ALL-NEXT: br i1 [[X_CURR_ISBITUNSET]], label [[LOOP]], label [[END:%.*]], [[DBG335:!dbg !.*]] ; ALL: end: ; ALL-NEXT: [[X_CURR_LCSSA:%.*]] = phi i32 [ [[X_CURR]], [[LOOP]] ], [[DBG331]] -; ALL-NEXT: call void @llvm.dbg.value(metadata i32 [[X_CURR_LCSSA]], [[META326]], metadata !DIExpression()), [[DBG331]] ; ALL-NEXT: ret i32 [[X_CURR_LCSSA]], [[DBG336:!dbg !.*]] ; entry: @@ -851,7 +829,6 @@ ; ALL-NEXT: br i1 [[X_CURR_ISBITUNSET]], label [[LOOP]], label [[END:%.*]], [[DBG348:!dbg !.*]] ; ALL: end: ; ALL-NEXT: [[X_CURR_LCSSA:%.*]] = phi i32 [ [[X_CURR]], [[LOOP]] ], [[DBG344]] -; ALL-NEXT: call void @llvm.dbg.value(metadata i32 [[X_CURR_LCSSA]], [[META339]], metadata !DIExpression()), [[DBG344]] ; ALL-NEXT: ret i32 [[X_CURR_LCSSA]], [[DBG349:!dbg !.*]] ; entry: @@ -891,7 +868,6 @@ ; ALL-NEXT: br i1 [[X_CURR_ISBITUNSET]], label [[LOOP]], label [[END:%.*]], [[DBG364:!dbg !.*]] ; ALL: end: ; ALL-NEXT: [[X_CURR_LCSSA:%.*]] = phi i32 [ [[X_CURR]], [[LOOP]] ], [[DBG359]] -; ALL-NEXT: call void @llvm.dbg.value(metadata i32 [[X_CURR_LCSSA]], [[META353]], metadata !DIExpression()), [[DBG359]] ; ALL-NEXT: ret i32 [[X_CURR_LCSSA]], [[DBG365:!dbg !.*]] ; entry: @@ -925,7 +901,6 @@ ; ALL-NEXT: br i1 [[X_CURR_ISBITUNSET]], label [[LOOP]], label [[END:%.*]], [[DBG376:!dbg !.*]] ; ALL: end: ; ALL-NEXT: [[X_CURR_LCSSA:%.*]] = phi i32 [ [[X_CURR]], [[LOOP]] ], [[DBG372]] -; ALL-NEXT: call void @llvm.dbg.value(metadata i32 [[X_CURR_LCSSA]], [[META368]], metadata !DIExpression()), [[DBG372]] ; ALL-NEXT: ret i32 [[X_CURR_LCSSA]], [[DBG377:!dbg !.*]] ; entry: @@ -962,7 +937,6 @@ ; ALL: end: ; ALL-NEXT: [[X_CURR_LCSSA:%.*]] = phi i32 [ [[X_CURR]], [[LOOP]] ], [[DBG387]] ; ALL-NEXT: [[X_CURR_BITMASKED_LCSSA:%.*]] = phi i32 [ [[X_CURR_BITMASKED]], [[LOOP]] ], [[DBG388]] -; ALL-NEXT: call void @llvm.dbg.value(metadata i32 [[X_CURR_LCSSA]], [[META381]], metadata !DIExpression()), [[DBG387]] ; ALL-NEXT: call void @use32(i32 [[X_CURR_BITMASKED_LCSSA]]), [[DBG392:!dbg !.*]] ; ALL-NEXT: ret i32 [[X_CURR_LCSSA]], [[DBG393:!dbg !.*]] ; @@ -1000,7 +974,6 @@ ; ALL: end: ; ALL-NEXT: [[X_CURR_LCSSA:%.*]] = phi i32 [ [[X_CURR]], [[LOOP]] ], [[DBG403]] ; ALL-NEXT: [[X_CURR_ISBITUNSET_LCSSA:%.*]] = phi i1 [ [[X_CURR_ISBITUNSET]], [[LOOP]] ], [[DBG405]] -; ALL-NEXT: call void @llvm.dbg.value(metadata i32 [[X_CURR_LCSSA]], [[META397]], metadata !DIExpression()), [[DBG403]] ; ALL-NEXT: call void @use1(i1 [[X_CURR_ISBITUNSET_LCSSA]]), [[DBG408:!dbg !.*]] ; ALL-NEXT: ret i32 [[X_CURR_LCSSA]], [[DBG409:!dbg !.*]] ; @@ -1038,7 +1011,6 @@ ; ALL: end: ; ALL-NEXT: [[X_CURR_LCSSA:%.*]] = phi i32 [ [[X_CURR]], [[LOOP]] ], [[DBG419]] ; ALL-NEXT: [[X_NEXT_LCSSA:%.*]] = phi i32 [ [[X_NEXT]], [[LOOP]] ], [[DBG422]] -; ALL-NEXT: call void @llvm.dbg.value(metadata i32 [[X_CURR_LCSSA]], [[META413]], metadata !DIExpression()), [[DBG419]] ; ALL-NEXT: call void @use32(i32 [[X_NEXT_LCSSA]]), [[DBG424:!dbg !.*]] ; ALL-NEXT: ret i32 [[X_CURR_LCSSA]], [[DBG425:!dbg !.*]] ;