https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121673
Bug ID: 121673 Summary: Missed optimization for arguments of calls to the same function Product: gcc Version: 16.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: antoshkka at gmail dot com Target Milestone: --- Consider the example: int func(int); int test(bool cond) { return cond ? func(1) : func(2); } GCC generates the following assembly: "test(bool)": test dil, dil je .L2 mov edi, 1 jmp "func(int)" .L2: mov edi, 2 jmp "func(int)" However a more compact and efficient assembly is possible: test(bool): mov eax, 2 sub eax, edi mov edi, eax jmp func(int)@PLT Godbolt playground https://godbolt.org/z/qrnz4TPfP