[llvm-bugs] [Bug 42672] New: DSE fails to remove stores to a structure overwritten by asm.

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jul 18 09:13:01 PDT 2019


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

            Bug ID: 42672
           Summary: DSE fails to remove stores to a structure overwritten
                    by asm.
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: glider at google.com
                CC: llvm-bugs at lists.llvm.org

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

-- 
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/20190718/149171a2/attachment-0001.html>


More information about the llvm-bugs mailing list