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: unassignedb...@nondot.org
          Reporter: gli...@google.com
                CC: craig.top...@gmail.com, llvm-bugs@lists.llvm.org,
                    llvm-...@redking.me.uk, spatel+l...@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to