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: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected]

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.
_______________________________________________
llvm-bugs mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to