[llvm-bugs] [Bug 43033] New: Inlined functions are not optimized as well as the same code copied in-line

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Aug 18 12:06:05 PDT 2019


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

            Bug ID: 43033
           Summary: Inlined functions are not optimized as well as the
                    same code copied in-line
           Product: new-bugs
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: henrik at gramner.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org

Minimal sample code:

static inline int imin(int a, int b) {
    return a < b ? a : b;
}

int fn1(int a, int b) {
    if (a < b) __builtin_unreachable();
    return imin(a, b);
}

int fn2(int a, int b) {
    if (a < b) __builtin_unreachable();
    return a < b ? a : b;
}


compiled with -O3 produces (Linux x86-64):

fn1:
        mov     eax, esi
        cmp     edi, esi
        cmovle  eax, edi
        ret
fn2:
        mov     eax, esi
        ret

Only in fn2 is the ternary operation correctly optimized away.

-- 
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/20190818/4f43182c/attachment.html>


More information about the llvm-bugs mailing list