Add @llvm.dbg.value entries for the phi node created by -mem2reg
authorKeith Walker <kwalker@arm.com>
Mon, 19 Sep 2016 09:49:30 +0000 (09:49 +0000)
committerKeith Walker <kwalker@arm.com>
Mon, 19 Sep 2016 09:49:30 +0000 (09:49 +0000)
commitc941252374b901333cb6e9c3fa0345890137e46e
treed0831bdba7c6be9ae45a581f7e2f55894e66ba3c
parente1f6dc59cefea03e5430e8d080195c58c595db7a
Add @llvm.dbg.value entries for the phi node created by -mem2reg

When phi nodes are created in the -mem2reg phase, the @llvm.dbg.declare
entries are converted to @llvm.dbg.value entries at the place where the
store instructions existed. However no entry is created to describe
the resulting value of the phi node.

The effect of this is especially noticeable in for loops which have a
constant for the intial value; the loop control variable's location
would be described as the intial constant value in the loop body once
the -mem2reg optimization phase was run.

This change adds the creation of the @llvm.dbg.value entries to describe
variables whose location is the result of a phi node created in -mem2reg.

Also when the phi node is finally lowered to a machine instruction it
is important that the lowered "load" instruction is placed before the
associated DEBUG_VALUE entry describing the value loaded.

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

llvm-svn: 281895
llvm/include/llvm/Transforms/Utils/Local.h
llvm/lib/Transforms/Utils/Local.cpp
llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
llvm/test/Transforms/Util/mem2reg-dbg.ll [new file with mode: 0644]