[DebugInfo][LCSSA] Rewrite pre-existing debug values outside loop
authorDavid Stenberg <david.stenberg@ericsson.com>
Tue, 16 Oct 2018 08:06:48 +0000 (08:06 +0000)
committerDavid Stenberg <david.stenberg@ericsson.com>
Tue, 16 Oct 2018 08:06:48 +0000 (08:06 +0000)
commitc9163855dd8b582f75921e01e903c3c27a57663d
tree96c544c3cf25ed72e0920c3bc38b0c014a4ed945
parent6a4f5e2addbddf32c54329d4e91aa830cd204e0f
[DebugInfo][LCSSA] Rewrite pre-existing debug values outside loop

Summary:
Extend LCSSA so that debug values outside loops are rewritten to
use the PHI nodes that the pass creates.

This fixes PR39019. In that case, we ran LCSSA on a loop that
was later on vectorized, which left us with something like this:

  for.cond.cleanup:
    %add.lcssa = phi i32 [ %add, %for.body ], [ %34, %middle.block ]
    call void @llvm.dbg.value(metadata i32 %add,
    ret i32 %add.lcssa

  for.body:
    %add =
    [...]
    br i1 %exitcond, label %for.cond.cleanup, label %for.body

which later resulted in the debug.value becoming undef when
removing the scalar loop (and the location would have probably
been wrong for the vectorized case otherwise).

As we now may need to query the AvailableVals cache more than
once for a basic block, FindAvailableVals() in SSAUpdaterImpl is
changed so that it updates the cache for blocks that we do not
create a PHI node for, regardless of the block's number of
predecessors. The debug value in the attached IR reproducer
would not be properly rewritten without this.

Debug values residing in blocks where we have not inserted any
PHI nodes are currently left as-is by this patch. I'm not sure
what should be done with those uses.

Reviewers: mattd, aprantl, vsk, probinson

Reviewed By: mattd, aprantl

Subscribers: jmorse, gbedwell, JDevlieghere, llvm-commits

Differential Revision: https://reviews.llvm.org/D53130

llvm-svn: 344589
llvm/include/llvm/Transforms/Utils/SSAUpdater.h
llvm/include/llvm/Transforms/Utils/SSAUpdaterImpl.h
llvm/lib/Transforms/Utils/LCSSA.cpp
llvm/lib/Transforms/Utils/SSAUpdater.cpp
llvm/test/Transforms/LCSSA/rewrite-existing-dbg-values.ll [new file with mode: 0644]