public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/116576] New: `INT64_MAX` and `-Oz`
@ 2024-09-03 6:14 lh_mouse at 126 dot com
2024-09-03 6:20 ` [Bug target/116576] " pinskia at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: lh_mouse at 126 dot com @ 2024-09-03 6:14 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116576
Bug ID: 116576
Summary: `INT64_MAX` and `-Oz`
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: lh_mouse at 126 dot com
Target Milestone: ---
For this simple function:
```
int64_t make_value(void) { return INT64_MAX; }
```
Both GCC and Clang generate an 8-byte `movabs` which adds up to 10 bytes:
```
48 b8 ffffffffffffff7f ; mov rax, 0x7fffffffffffffff
; (10 bytes; no dependency)
```
When we do `-Oz` we otpimize for size and do not care about the false
dependency, and this can be accomplished in only 7 bytes:
```
48 83 c8 ff ; or rax, -1
48 d1 e8 ; shr rax
; (7 bytes; input dependency on rax)
```
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug target/116576] `INT64_MAX` and `-Oz`
2024-09-03 6:14 [Bug target/116576] New: `INT64_MAX` and `-Oz` lh_mouse at 126 dot com
@ 2024-09-03 6:20 ` pinskia at gcc dot gnu.org
2024-09-03 6:51 ` lh_mouse at 126 dot com
2024-09-09 7:55 ` roger at nextmovesoftware dot com
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-09-03 6:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116576
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug target/116576] `INT64_MAX` and `-Oz`
2024-09-03 6:14 [Bug target/116576] New: `INT64_MAX` and `-Oz` lh_mouse at 126 dot com
2024-09-03 6:20 ` [Bug target/116576] " pinskia at gcc dot gnu.org
@ 2024-09-03 6:51 ` lh_mouse at 126 dot com
2024-09-09 7:55 ` roger at nextmovesoftware dot com
2 siblings, 0 replies; 4+ messages in thread
From: lh_mouse at 126 dot com @ 2024-09-03 6:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116576
--- Comment #1 from LIU Hao <lh_mouse at 126 dot com> ---
Here is a longer solution but it breaks the dependency:
```
31c0 ; xor eax, eax
48 ffc8 ; dec rax
48 d1e8 ; shr rax
; (8 bytes; no dependency)
```
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug target/116576] `INT64_MAX` and `-Oz`
2024-09-03 6:14 [Bug target/116576] New: `INT64_MAX` and `-Oz` lh_mouse at 126 dot com
2024-09-03 6:20 ` [Bug target/116576] " pinskia at gcc dot gnu.org
2024-09-03 6:51 ` lh_mouse at 126 dot com
@ 2024-09-09 7:55 ` roger at nextmovesoftware dot com
2 siblings, 0 replies; 4+ messages in thread
From: roger at nextmovesoftware dot com @ 2024-09-09 7:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116576
Roger Sayle <roger at nextmovesoftware dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
CC| |roger at nextmovesoftware dot com
Ever confirmed|0 |1
Last reconfirmed| |2024-09-09
--- Comment #2 from Roger Sayle <roger at nextmovesoftware dot com> ---
The constant ~0 can be materialized on x86 in only three bytes using either of
the sequences "push -1; pop rax" (i.e. 6a ff 58) or "stc; sbb ax,ax" (i.e. f9
19 c0), both of which could theoretically be fused/optimized/avoid dependencies
on modern hardware. With -Oz, GCC mainline and clang currently use the first
sequence.
But you're absolutely right that following this by a logical shift can be used
to materialize INT64_MAX (and other constants) in fewer bytes than the standard
movabs when its safe to clobber the flags.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-09-09 7:55 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-03 6:14 [Bug target/116576] New: `INT64_MAX` and `-Oz` lh_mouse at 126 dot com
2024-09-03 6:20 ` [Bug target/116576] " pinskia at gcc dot gnu.org
2024-09-03 6:51 ` lh_mouse at 126 dot com
2024-09-09 7:55 ` roger at nextmovesoftware dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).