[llvm-bugs] [Bug 48206] New: insertDebugValuesForPHIs() re-orders how assignments appear

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Nov 17 08:26:12 PST 2020


https://bugs.llvm.org/show_bug.cgi?id=48206

            Bug ID: 48206
           Summary: insertDebugValuesForPHIs() re-orders how assignments
                    appear
           Product: new-bugs
           Version: unspecified
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: Nabeel.Omer at sony.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org

Version: LLVM 12.0 built from master at
bb8d1437a6fb3816c21363506ccb109adda58fb3

The LCSSA pass makes use of a function `insertDebugValuesForPHIs()` to
propogate `dbg.value()` intrinsics to newly inserted PHI instructions.

This bug occurs when the associated parent PHI of a newly inserted PHI is not
the most recent assignment to a source variable.

## Example:

```
; input.ll:
%S2 = ...
br label %loop.interior
loop.interior:
    br i1 %S2, label %if.true, label %if.false                    
if.true:
    %X1 = ...
    @llvm.dbg.value(var = %X1)  
    br label %post.if

if.false:                         
    %X2 = ...
    @llvm.dbg.value(var = %X2)  
    br label %post.if

post.if:
    %X3 = phi(X1, X2)            
    @llvm.dbg.value(var = %X3)  

    %Y1 = ...                    
    @llvm.dbg.value(var = %Y1)

    br i1 %S2, label %loop.exit, label %loop.interior

loop.exit:
    ... = X3 + 4


; output.ll:
%S2 = ...
br label %loop.interior
loop.interior:
    br i1 %S2, label %if.true, label %if.false                       
if.true:
    %X1 = ...
    @llvm.dbg.value(var = %X1)  
    br label %post.if

if.false:                         
    %X2 = ...
    @llvm.dbg.value(var = %X2)  
    br label %post.if

post.if:
    %X3 = phi(X1, X2)            
    @llvm.dbg.value(var = %X3)  

    %Y1 = ...                    
    @llvm.dbg.value(var = %Y1)

    br i1 %S2, label %loop.exit, label %loop.interior

loop.exit:
    %X3.lcssa = phi(X3)
    @llvm.dbg.value(var = %X3.lcssa) <---- Incorrect!
    %X4 = %X3.lcssa + 3
```

As can be seen in the pseudo-IR above, insertDebugValuesForPHIs() propogates
the incorrect `dbg.value()` intrinsic. The intrinsic that should be propogated
is the one associated with `%Y1` because that is the most recent assignment to
`var`, but it is simply ignored. This results in incorrect debugging
information.

In terms of the code listings below, the problem is that in the `post.if` block
in `input.ll`, after the assignment to `%X3` and the associated `dbg.value()`
intrinsic making an assignment to the source variable `var`, there's another
assignment to `%Y1` and an associated `dbg.value()` intrinsic that makes `%Y1`
the most recent assignment to the source variable `var`(`!6`).
`insertDebugValuesForPHIs()` the function responsible for propogating the
intrinsic to the newly inserted PHI in `loop.exit` ignores the assignment to
`%Y1` and simply propogates the intrinsic associated with `%X3` as can be seen
in `output.ll`. This results in incorrect debugging information.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20201117/858d140b/attachment.html>


More information about the llvm-bugs mailing list