Consider the example: int test (bool x) { return '0' + x; } For the above snippet the following suboptimal assembly is generated: test(bool): movzx eax, dil add eax, 48 ret More efficient assembly would be: test(bool): lea eax, [rdi + 48] ret
For which ABI do you propose the change? It's not correct for GNU/Linux: “When a value of type _Bool is returned or passed in a register or on the stack, bit 0 contains the truth value and bits 1 to 7 shall be zero.” And the footnote says: “Other bits are left unspecified, hence the consumer side of those values can rely on it being 0 or 1 when truncated to 8 bit.”
(In reply to Florian Weimer from comment #1) > For which ABI do you propose the change? It's not correct for GNU/Linux: As far as I understand the proposed change does not touch ABI. `lea eax, [rdi + 48]` is equivalent to `movzx+add`
(In reply to Antony Polukhin from comment #2) > (In reply to Florian Weimer from comment #1) > > For which ABI do you propose the change? It's not correct for GNU/Linux: > > As far as I understand the proposed change does not touch ABI. `lea eax, > [rdi + 48]` is equivalent to `movzx+add` According to the x86-64 psABI, for bool, only the lower 8 bits of the register are defined when passing a bool value. This means that the movzx instruction is not optional because the int result needs all 32 bits defined. GCC already uses lea in cases where the upper 24 bits do not matter, as in this example: char test (bool x) { return '0' + x; }
Sorry, now I understood that the bug is invalid. Please close.
Closing.