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

            Bug ID: 43252
           Summary: Unnecessary mov instruction
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangb...@nondot.org
          Reporter: tspit...@ieee.org
                CC: htmldevelo...@gmail.com, llvm-bugs@lists.llvm.org,
                    neeil...@live.com, richard-l...@metafoo.co.uk

For the following code

    void foo(int i);
    void bar(int i) {
        if (i != 0)
            foo(i);
        bar(i);
    }

clang -O3 -S produces this (cleaned up)

    bar:
        pushq   %rbx
        movl    %edi, %ebx
        testl   %edi, %edi
        je      .LBB0_2
        movl    %ebx, %edi
        callq   foo
    .LBB0_2:
        movl    %ebx, %edi
        popq    %rbx
        jmp     foo

The marked mov instruction is not necessary, as edi is already equal to ebx.

Also, the LBB0_2 label can move down one line to just before the popq
instrucion, as if the branch is taken then edi is still equal to ebx.

This is for clang 8.0 on Fedora 30. clang --version produces

    clang version 8.0.0 (Fedora 8.0.0-1.fc30)
    Target: x86_64-unknown-linux-gnu
    Thread model: posix
    InstalledDir: /usr/bin

-- 
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