Skip to content

Inlined functions are not optimized as well as the same code copied in-line #42378

@Gramner

Description

@Gramner
Bugzilla Link 43033
Version trunk
OS All
CC @dwblaikie,@fhahn,@rotateright

Extended Description

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions