Skip to content

Commit

Permalink
[Debug] Add dbg.value intrinsics for PHIs created during LCSSA.
Browse files Browse the repository at this point in the history
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

llvm-svn: 323472
  • Loading branch information
vedantk committed Jan 25, 2018
1 parent 6bfc869 commit 60f5408
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 7 additions & 2 deletions llvm/lib/Transforms/Utils/LCSSA.cpp
Expand Up @@ -43,6 +43,7 @@
#include "llvm/IR/PredIteratorCache.h"
#include "llvm/Pass.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Transforms/Utils/LoopUtils.h"
#include "llvm/Transforms/Utils/SSAUpdater.h"
using namespace llvm;
Expand Down Expand Up @@ -214,11 +215,15 @@ bool llvm::formLCSSAForInstructions(SmallVectorImpl<Instruction *> &Worklist,
Worklist.push_back(PostProcessPN);

// Keep track of PHI nodes that we want to remove because they did not have
// any uses rewritten.
// any uses rewritten. If the new PHI is used, store it so that we can
// try to propagate dbg.value intrinsics to it.
SmallVector<PHINode *, 2> NeedDbgValues;
for (PHINode *PN : AddedPHIs)
if (PN->use_empty())
PHIsToRemove.insert(PN);

else
NeedDbgValues.push_back(PN);
insertDebugValuesForPHIs(InstBB, NeedDbgValues);
Changed = true;
}
// Remove PHI nodes that did not have any uses rewritten.
Expand Down
2 changes: 2 additions & 0 deletions llvm/test/Transforms/LCSSA/basictest.ll
@@ -1,5 +1,6 @@
; RUN: opt < %s -lcssa -S | FileCheck %s
; RUN: opt < %s -passes=lcssa -S | FileCheck %s
; RUN: opt < %s -debugify -lcssa -S | FileCheck -check-prefix=CHECK2 %s

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

0 comments on commit 60f5408

Please sign in to comment.