Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit b7162f2

Browse files
committed
[Debug] Add dbg.value intrinsics for PHIs created during LCSSA.
This patch is an enhancement to propagate dbg.value information when Phis are created on behalf of LCSSA. I noticed a case where a value carried across a loop was reported as <optimized out>. Specifically this case: int bar(int x, int y) { return x + y; } int foo(int size) { int val = 0; for (int i = 0; i < size; ++i) { val = bar(val, i); // Both val and i are correct } return val; // <optimized out> } In the above case, after all of the interesting computation completes our value is reported as "optimized out." This change will add a dbg.value to correct this. This patch also moves the dbg.value insertion routine from LoopRotation.cpp into Local.cpp, so that we can share it in both places (LoopRotation and LCSSA). Patch by Matt Davis! Differential Revision: https://reviews.llvm.org/D42551 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@323472 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent cdd614d commit b7162f2

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/Transforms/Utils/LCSSA.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "llvm/IR/PredIteratorCache.h"
4444
#include "llvm/Pass.h"
4545
#include "llvm/Transforms/Scalar.h"
46+
#include "llvm/Transforms/Utils/Local.h"
4647
#include "llvm/Transforms/Utils/LoopUtils.h"
4748
#include "llvm/Transforms/Utils/SSAUpdater.h"
4849
using namespace llvm;
@@ -214,11 +215,15 @@ bool llvm::formLCSSAForInstructions(SmallVectorImpl<Instruction *> &Worklist,
214215
Worklist.push_back(PostProcessPN);
215216

216217
// Keep track of PHI nodes that we want to remove because they did not have
217-
// any uses rewritten.
218+
// any uses rewritten. If the new PHI is used, store it so that we can
219+
// try to propagate dbg.value intrinsics to it.
220+
SmallVector<PHINode *, 2> NeedDbgValues;
218221
for (PHINode *PN : AddedPHIs)
219222
if (PN->use_empty())
220223
PHIsToRemove.insert(PN);
221-
224+
else
225+
NeedDbgValues.push_back(PN);
226+
insertDebugValuesForPHIs(InstBB, NeedDbgValues);
222227
Changed = true;
223228
}
224229
// Remove PHI nodes that did not have any uses rewritten.

test/Transforms/LCSSA/basictest.ll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
; RUN: opt < %s -lcssa -S | FileCheck %s
22
; RUN: opt < %s -passes=lcssa -S | FileCheck %s
3+
; RUN: opt < %s -debugify -lcssa -S | FileCheck -check-prefix=CHECK2 %s
34

45
define void @lcssa(i1 %S2) {
56
; CHECK-LABEL: @lcssa
@@ -18,6 +19,7 @@ post.if: ; preds = %if.false, %if.true
1819
br i1 %S2, label %loop.exit, label %loop.interior
1920
loop.exit: ; preds = %post.if
2021
; CHECK: %X3.lcssa = phi i32
22+
; CHECK2: call void @llvm.dbg.value(metadata i32 %X3.lcssa, metadata !11, metadata !DIExpression()), !dbg !19
2123
; CHECK: %X4 = add i32 3, %X3.lcssa
2224
%X4 = add i32 3, %X3 ; <i32> [#uses=0]
2325
ret void

0 commit comments

Comments
 (0)