This is an archive of the discontinued LLVM Phabricator instance.

[DebugInfo][dexter] Add dexter tests for merged values
ClosedPublic

Authored by Orlando on Jan 15 2021, 3:19 AM.

Details

Summary

These dexter tests illustrate PR48719, the summary of which is:

Sometimes we insert dbg.values for merged values (PHIs) when promoting
variables, sometimes we don't. Sometimes there is no PHI because the merged
value is never used. It doesn't matter because LiveDebugValues understands
these merged values (implicit or otherwise) and correctly updates the debug
info. Importantly, these merged variable values (which may or may not exist as
PHIs, and may or not be represented with dbg.values) are always implicitly
defined by the combination of incoming edges and the incoming variable
locations along those edges by virtue of LiveDebugValues
existing. Unfortunately, it is possible to mess with the CFG and remove / move
these edges before LiveDebugValues runs. In this case our debug info model only
works when the merged value is tracked by a dbg.value. Currently, this is only
done rigorously for variables which are A) promoted in the first round of
mem2reg and B) are used after the merge point.

As an example, compile the following source with -O3 -g and step through
with a debugger. You will see parama=5 throughout the function fun which
is incorrect - we expect to see param=20 after the conditional assignment.

__attribute__((optnone))
void esc(int* p) {}

__attribute__((optnone))
void fluff() {}

__attribute__((noinline))
int fun(int parama, int paramb) {
  if (parama)
    parama = paramb;
  fluff();           // DexLabel('s0')
  esc(&parama);
  return 0;
}

int main() {
  return fun(5, 20);
}
  1. parama is escaped by esc(&parama) so it is not promoted by SROA/mem2reg (failing condition "A" above).
  2. InstCombine's LowerDbgDeclare converts the dbg.declare to a set of dbg.values (tracking the stored SSA values).
  3. InstCombine replaces the two stores to parama's alloca (the initial parameter register store in entry and the assignment in if.then) with a PHI+store in the common sucessor.
  4. SimplifyCFG folds the blocks together and converts the PHI to a select.

The debug info is not updated to account for the merged value in the successor
prior to SimplifyCFG when it exists as a PHI, or during when it becomes a
select.

As with D89543, which added some dexter tests for escaped locals, the idea is
to build a set of source-level tests which highlights existing issues and
might be useful in evaluating a new debug info model.

Diff Detail

Event Timeline

Orlando requested review of this revision.Jan 15 2021, 3:19 AM
Orlando created this revision.
rnk accepted this revision.Jan 15 2021, 4:35 PM

lgtm

This revision is now accepted and ready to land.Jan 15 2021, 4:35 PM
This revision was automatically updated to reflect the committed changes.