[llvm-bugs] [Bug 43252] New: Unnecessary mov instruction

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Sep 9 01:59:36 PDT 2019


            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: unassignedclangbugs at nondot.org
          Reporter: tspiteri at ieee.org
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    neeilans at live.com, richard-llvm at metafoo.co.uk

For the following code

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

clang -O3 -S produces this (cleaned up)

        pushq   %rbx
        movl    %edi, %ebx
        testl   %edi, %edi
        je      .LBB0_2
        movl    %ebx, %edi
        callq   foo
        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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190909/96f1d558/attachment.html>

More information about the llvm-bugs mailing list