[llvm-bugs] [Bug 38335] New: Missed optimization of functions deduplication

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Jul 27 03:04:54 PDT 2018


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

            Bug ID: 38335
           Summary: Missed optimization of functions deduplication
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: antoshkka at gmail.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

If two functions have the same body Clang does not deduplicate the functions.

Consider the following example:

void mutate0(int&);

template <int I>
int foo_template(int b) {
    mutate0(b); mutate0(b); mutate0(b); mutate0(b);
    mutate0(b); mutate0(b); mutate0(b); mutate0(b);
    mutate0(b); mutate0(b); mutate0(b); mutate0(b);
    return b;
}

int foo0(int b) {
    return foo_template<0>(b);
}

int foo1(int b) {
    return foo_template<1>(b);
}


GCC deduplicates the function bodies and foo1 and foo2 and call the same
template instantiation:
_Z4foo0i:
  jmp _Z12foo_templateILi0EEii
_Z4foo1i:
  jmp _Z12foo_templateILi0EEii  # Same as above


Clang instead produces functions that call different template instantiations:
_Z4foo0i:                               
        jmp     _Z12foo_templateILi0EEii
_Z4foo1i:                               
        jmp     _Z12foo_templateILi1EEii # Differs from above!


This results in a two times bigger assembly on Clang.

-- 
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/20180727/b5342335/attachment-0001.html>


More information about the llvm-bugs mailing list