https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122532
Bug ID: 122532
Summary: Compilation with -Oz --- does not reuse known register
values
Product: gcc
Version: 15.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: zero at smallinteger dot com
Target Milestone: ---
Created attachment 62691
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=62691&action=edit
Sample code
Consider the attached code compiled with -Oz. Per Godbolt, gcc 15.2 yields the
following.
test:
push 66
pop rax
mov QWORD PTR [rdi], 66
mov QWORD PTR [rdi+8], 66
mov QWORD PTR [rdi+16], 66
ret
Note the memory stores do not reuse the known value of rax. Consequently, the
emitted code is larger than what it could be. For comparison, clang does this
with -Oz.
test:
push 66
pop rax
mov qword ptr [rdi], rax
mov qword ptr [rdi + 8], rax
mov qword ptr [rdi + 16], rax
ret