When we sink DBG_VALUEs at the moment, we simply move the DBG_VALUE instruction to below the sunk instruction. However, we should also mark the variable as being undef at the source location, to terminate any earlier variable location. This patch does that -- plus, if the instruction being sunk is a copy, it attempts to propagate the copy through the DBG_VALUE, replacing the destination with the source.
To avoid any kind of subregister shennanigans, vreg copy propagation only happens if all the subregisters agree; for physical registers we only propagate if the DBG_VALUE operand is the same as the destination of the copy. So:
%1 = COPY %0 DBG_VALUE %1
Would copy-prop, while
%1 = COPY %0 DBG_VALUE %1.subreg_8bit
Would not. Additional analysis might determine this to be safe, but I haven't implemented it here.
Likewise after regalloc:
$eax = COPY $ecx DBG_VALUE $eax
Would constant-prop, while
$ax = $cx DBG_VALUE $eax
Would not.
With this patch, building clang-3.4 yields a fractional number more number of covered variables, and roughly 0.5% more scope-bytes coverage.