Bug 108371 - gcc for x86_64 may sign/zero extent arguments unnecessarily
Summary: gcc for x86_64 may sign/zero extent arguments unnecessarily
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 12.2.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2023-01-11 14:04 UTC by dhowells@redhat.com
Modified: 2023-01-11 14:28 UTC (History)
0 users

See Also:
Host:
Target: x86_64-*-*
Build:
Known to work:
Known to fail:
Last reconfirmed: 2023-01-11 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description dhowells@redhat.com 2023-01-11 14:04:40 UTC
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
Comment 1 Richard Biener 2023-01-11 14:28:51 UTC
Confirmed.  This is the C frontend doing

;; Function bio_release_pages (null)
;; enabled by -tree-original


{
  __bio_release_pages ((int) mark_dirty);
}

aka targetm.calls.promote_prototypes