<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - LiveDebugVariables propagates constant values without joining at bb boundaries"
   href="https://llvm.org/bugs/show_bug.cgi?id=24563">24563</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>LiveDebugVariables propagates constant values without joining at bb boundaries
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>DebugInfo
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>aprantl@apple.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Found while reviewing <a href="http://reviews.llvm.org/D11933">http://reviews.llvm.org/D11933</a>

Compiling the following testcase at -O1

void g(int *);
int f() {
  int x = 23;
  g(&x);
  if (x == 42)
    ++x;
  return x;
}

will cause the constant value 23 to be propagated into the last basic block:

BB#2: derived from LLVM BB %if.end
    Predecessors according to CFG: BB#0 BB#1
  DBG_VALUE 23, 0, !"x", <!14>; line no:3
  %EAX<def> = MOV32rm %RSP, 1, %noreg, 4, %noreg; mem:LD4[%x](tbaa=!17)
dbg:r.c:7:10
  %RDX<def> = POP64r %RSP<imp-def>, %RSP<imp-use>; dbg:r.c:7:3
  RETQ %EAX; dbg:r.c:7:3


Looking into this I found that LiveDebugVariables is the culprit here:

  void UserValue::extendDef(SlotIndex Idx, unsigned LocNo,
                            LiveRange *LR, const VNInfo *VNI,
                            SmallVectorImpl<SlotIndex> *Kills,
                            LiveIntervals &LIS, MachineDominatorTree &MDT,
                            UserValueScopes &UVS) {
      ...
      for (unsigned i = 0, e = Children.size(); i != e; ++i) {
        MachineBasicBlock *MBB = Children[i]->getBlock();
        if (UVS.dominates(MBB))
          Todo.push_back(LIS.getMBBStartIdx(MBB));
    }
  }

It look like it just unconditionally propagates all DBG_VALUEs down the
dominator tree, which happens to work fine if there already is another
DBG_VALUE but is wrong if the DBG_VALUE is coming from only one of the
predecessors like in this example here.

The DBG_VALUES should only end up in a subsequent basic block if they appear at
the end of all predecessors.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>