https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108371
Bug ID: 108371 Summary: gcc for x86_64 may sign/zero extent arguments unnecessarily Product: gcc Version: 12.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: dhowells at redhat dot com Target Milestone: --- When compiling for x86_64, bool, char and short arguments that are passed directly to an argument of exactly the same type on another function with no modification, e.g.: void __bio_release_pages(char mark_dirty); void bio_release_pages(char mark_dirty) { __bio_release_pages(mark_dirty); } get sign/zero-extended unnecessarily. In the case of the above code, it compiles to: 0: 40 0f be ff movsbl %dil,%edi 4: e9 00 00 00 00 jmp 9 <bio_release_pages+0x9> with "gcc -Os -c test.c". Can the extension be optimised away? Granted, the upper bits bits of RDI could contain rubbish on entry to bio_release_pages(), so sanitisation is not unreasonable - but on the other hand, __bio_release_pages() would surely have to assume the same and do the same sanitisation? The toolchain used is the Fedora 37 system compiler: gcc-12.2.1-4.fc37.x86_64 binutils-2.38-25.fc37.x86_64