<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - DSE fails to remove stores to a structure overwritten by asm."
   href="https://bugs.llvm.org/show_bug.cgi?id=42672">42672</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>DSE fails to remove stores to a structure overwritten by asm.
          </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>Linux
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Scalar Optimizations
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>glider@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>In the following example:

void  _raw_spin_lock(void)
{
#if STRUCT
  struct {
    unsigned short owner, next;
  } lockval;
  lockval.owner = 1;
  lockval.next = 2;
#else
  int lockval;
  lockval = 3;
#endif
  asm ("nop" : "=r" (lockval));
}

|lockval| is declared as assembly output that is overwritten by the inline
assembly (as specified by constraints).
If |lockval| is a scalar type, its initialization is correctly omitted.
However if |lockval| is a struct, DSE is unable to figure out that the stores
to its fields are effectively dead:

$ clang -O2 -USTRUCT -c spinlock.c && objdump -d spinlock.o

spinlock.o:     file format elf64-x86-64


Disassembly of section .text:

0000000000000000 <_raw_spin_lock>:
   0:   c3                      retq   


$ clang -O2 -DSTRUCT -c spinlock.c && objdump -d spinlock.o

spinlock.o:     file format elf64-x86-64


Disassembly of section .text:

0000000000000000 <_raw_spin_lock>:
   0:   c7 44 24 f8 01 00 02    movl   $0x20001,-0x8(%rsp)
   7:   00 
   8:   90                      nop
   9:   c3                      retq</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>