[llvm-bugs] [Bug 40527] New: Missed opportunity to remove a dead store

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jan 30 05:56:10 PST 2019


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

            Bug ID: 40527
           Summary: Missed opportunity to remove a dead store
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: X86
          Assignee: unassignedbugs at nondot.org
          Reporter: glider at google.com
                CC: craig.topper at gmail.com, llvm-bugs at lists.llvm.org,
                    llvm-dev at redking.me.uk, spatel+llvm at rotateright.com

When compiling the following code:

============================
  void alloc_sock(int *err);
  int try_send();

  int send(int len) {
    int err;
    if (len) {
      err = -1; 
      alloc_sock(&err);
      err = try_send();
    }
    return -1; 
  }
============================

with 
 $ clang -O2  -g -ftrivial-auto-var-init=pattern
-enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang -c t.c

Clang produces an extra store of $0xaaaaaaaa to |err|, which is introduced by
the -ftrivial-auto-var-init and not removed by other optimizations in the
pipeline:

$ objdump -d t.o

0000000000000000 <send>:
   0:   50                      push   %rax
   1:   c7 44 24 04 aa aa aa    movl   $0xaaaaaaaa,0x4(%rsp)
   8:   aa 
   9:   85 ff                   test   %edi,%edi
   b:   74 1d                   je     2a <send+0x2a>
   d:   c7 44 24 04 ff ff ff    movl   $0xffffffff,0x4(%rsp)
  14:   ff 
  15:   48 8d 7c 24 04          lea    0x4(%rsp),%rdi
  1a:   e8 00 00 00 00          callq  1f <send+0x1f>
  1f:   31 c0                   xor    %eax,%eax
  21:   e8 00 00 00 00          callq  26 <send+0x26>
  26:   89 44 24 04             mov    %eax,0x4(%rsp)
  2a:   b8 ff ff ff ff          mov    $0xffffffff,%eax
  2f:   59                      pop    %rcx
  30:   c3                      retq  

As noted by JF Bastien here: https://reviews.llvm.org/D54604, "Seems like the
optimizer should sink the store enough that it appears only once on each path."

-- 
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/20190130/0023dbd1/attachment.html>


More information about the llvm-bugs mailing list