public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/103541] New: unnecessary spills around const functions calls
@ 2021-12-03 15:16 hubicka at gcc dot gnu.org
2021-12-03 20:35 ` [Bug rtl-optimization/103541] " pinskia at gcc dot gnu.org
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: hubicka at gcc dot gnu.org @ 2021-12-03 15:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103541
Bug ID: 103541
Summary: unnecessary spills around const functions calls
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: rtl-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: hubicka at gcc dot gnu.org
Target Milestone: ---
While looking into reasons why modref causes some code size increases I noticed
that we produce unnecessary spill on x86-64 here:
float a;
__attribute__((const)) float foo (float);
float
test()
{
return a + foo(a) + a;
}
we load "a" into register and then spill it to stack because all SSE registers
are clobbered by the call. This seems to happen somewhere between gcc 4.1 and
4.6. It is caused by:
/* We can combine a reg def from one insn into a reg use in
another over a call if the memory is readonly or the call
const/pure. However, we can't set reg_equiv notes up for
reload over any call. The problem is the equivalent form
may reference a pseudo which gets assigned a call
clobbered hard reg. When we later replace REG with its
equivalent form, the value in the call-clobbered reg has
been changed and all hell breaks loose. */
ret = valid_combine;
if (!MEM_READONLY_P (memref)
&& !RTL_CONST_OR_PURE_CALL_P (insn))
return valid_none;
in ira.c:validate_equiv_mem
If I read the comment correctly it is afraid of the address of memory reading
being altered by the call (using call clobbered registers). But here it is a
constant, so perhaps we can just rule this out when MEM rtx does not mention
registers or does not mention any callee clobbered registers?
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug rtl-optimization/103541] unnecessary spills around const functions calls
2021-12-03 15:16 [Bug rtl-optimization/103541] New: unnecessary spills around const functions calls hubicka at gcc dot gnu.org
@ 2021-12-03 20:35 ` pinskia at gcc dot gnu.org
2021-12-03 20:35 ` pinskia at gcc dot gnu.org
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-03 20:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103541
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I thought I had seen this before ...
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug rtl-optimization/103541] unnecessary spills around const functions calls
2021-12-03 15:16 [Bug rtl-optimization/103541] New: unnecessary spills around const functions calls hubicka at gcc dot gnu.org
2021-12-03 20:35 ` [Bug rtl-optimization/103541] " pinskia at gcc dot gnu.org
@ 2021-12-03 20:35 ` pinskia at gcc dot gnu.org
2021-12-03 20:37 ` pinskia at gcc dot gnu.org
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-03 20:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103541
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=5739
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
PR 5739 is related (though I have not looked fully).
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug rtl-optimization/103541] unnecessary spills around const functions calls
2021-12-03 15:16 [Bug rtl-optimization/103541] New: unnecessary spills around const functions calls hubicka at gcc dot gnu.org
2021-12-03 20:35 ` [Bug rtl-optimization/103541] " pinskia at gcc dot gnu.org
2021-12-03 20:35 ` pinskia at gcc dot gnu.org
@ 2021-12-03 20:37 ` pinskia at gcc dot gnu.org
2023-02-03 23:15 ` vmakarov at gcc dot gnu.org
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-03 20:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103541
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #2)
> PR 5739 is related (though I have not looked fully).
comment #10 which points out IRA was doing worse.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug rtl-optimization/103541] unnecessary spills around const functions calls
2021-12-03 15:16 [Bug rtl-optimization/103541] New: unnecessary spills around const functions calls hubicka at gcc dot gnu.org
` (2 preceding siblings ...)
2021-12-03 20:37 ` pinskia at gcc dot gnu.org
@ 2023-02-03 23:15 ` vmakarov at gcc dot gnu.org
2023-02-07 14:05 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: vmakarov at gcc dot gnu.org @ 2023-02-03 23:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103541
Vladimir Makarov <vmakarov at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |vmakarov at gcc dot gnu.org
--- Comment #4 from Vladimir Makarov <vmakarov at gcc dot gnu.org> ---
Honza, thank you for reporting this. Fixing just the following code will not
solve the problem as LRA uses only equiv expression valid for the whole
function.
> ret = valid_combine;
> if (!MEM_READONLY_P (memref)
> && !RTL_CONST_OR_PURE_CALL_P (insn))
> return valid_none;
>
By the way, the old reload pass still works on the test and producing the same
code as LRA currently, also reserving stack slot and using it around the call
instead of reload from a.
I've been working on this problem and I hope the fix will be ready on the next
week.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug rtl-optimization/103541] unnecessary spills around const functions calls
2021-12-03 15:16 [Bug rtl-optimization/103541] New: unnecessary spills around const functions calls hubicka at gcc dot gnu.org
` (3 preceding siblings ...)
2023-02-03 23:15 ` vmakarov at gcc dot gnu.org
@ 2023-02-07 14:05 ` cvs-commit at gcc dot gnu.org
2023-02-08 22:30 ` hjl.tools at gmail dot com
2023-02-09 21:48 ` cvs-commit at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-02-07 14:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103541
--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Vladimir Makarov <vmakarov@gcc.gnu.org>:
https://gcc.gnu.org/g:f661c0bb6371f355966a67b5ce71398e80792948
commit r13-5730-gf661c0bb6371f355966a67b5ce71398e80792948
Author: Vladimir N. Makarov <vmakarov@redhat.com>
Date: Tue Feb 7 08:27:36 2023 -0500
RA: Implement reuse of equivalent memory for caller saves optimization
The test case shows opportunity to reuse memory with constant address for
caller saves optimization for constant or pure function call. The patch
implements the memory reuse.
PR rtl-optimization/103541
gcc/ChangeLog:
* ira.h (struct ira_reg_equiv_s): Add new field caller_save_p.
* ira.cc (validate_equiv_mem): Check memref address variance.
(update_equiv_regs): Define caller save equivalence for
valid_combine.
(setup_reg_equiv): Clear defined_p flag for caller save
equivalence.
* lra-constraints.cc (lra_copy_reg_equiv): Add new arg
call_save_p. Use caller save equivalence depending on the arg.
(split_reg): Adjust the call.
gcc/testsuite/ChangeLog:
* gcc.target/i386/pr103541.c: New.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug rtl-optimization/103541] unnecessary spills around const functions calls
2021-12-03 15:16 [Bug rtl-optimization/103541] New: unnecessary spills around const functions calls hubicka at gcc dot gnu.org
` (4 preceding siblings ...)
2023-02-07 14:05 ` cvs-commit at gcc dot gnu.org
@ 2023-02-08 22:30 ` hjl.tools at gmail dot com
2023-02-09 21:48 ` cvs-commit at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: hjl.tools at gmail dot com @ 2023-02-08 22:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103541
--- Comment #6 from H.J. Lu <hjl.tools at gmail dot com> ---
The change has been reverted by r13-5738-gad2bd0ad0413c2448fee0d4a
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug rtl-optimization/103541] unnecessary spills around const functions calls
2021-12-03 15:16 [Bug rtl-optimization/103541] New: unnecessary spills around const functions calls hubicka at gcc dot gnu.org
` (5 preceding siblings ...)
2023-02-08 22:30 ` hjl.tools at gmail dot com
@ 2023-02-09 21:48 ` cvs-commit at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-02-09 21:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103541
--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Vladimir Makarov <vmakarov@gcc.gnu.org>:
https://gcc.gnu.org/g:10827a92f1a8c3207b327515f77845b34c1d9512
commit r13-5761-g10827a92f1a8c3207b327515f77845b34c1d9512
Author: Vladimir N. Makarov <vmakarov@redhat.com>
Date: Thu Feb 9 15:18:48 2023 -0500
RA: Implement reuse of equivalent memory for caller saves optimization (2nd
version)
The test pr103541.c shows opportunity to reuse memory with constant address
for
caller saves optimization for constant or pure function call. The patch
implements the memory reuse.
PR rtl-optimization/103541
PR rtl-optimization/108711
gcc/ChangeLog:
* ira.h (struct ira_reg_equiv_s): Add new field caller_save_p.
* ira.cc (validate_equiv_mem): Check memref address variance.
(no_equiv): Clear caller_save_p flag.
(update_equiv_regs): Define caller save equivalence for
valid_combine.
(setup_reg_equiv): Clear defined_p flag for caller save
equivalence.
* lra-constraints.cc (lra_copy_reg_equiv): Add new arg
call_save_p. Use caller save equivalence depending on the arg.
(split_reg): Adjust the call.
gcc/testsuite/ChangeLog:
* gcc.target/i386/pr103541.c: New.
* g++.target/i386/pr108711.C: New.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2023-02-09 21:48 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-03 15:16 [Bug rtl-optimization/103541] New: unnecessary spills around const functions calls hubicka at gcc dot gnu.org
2021-12-03 20:35 ` [Bug rtl-optimization/103541] " pinskia at gcc dot gnu.org
2021-12-03 20:35 ` pinskia at gcc dot gnu.org
2021-12-03 20:37 ` pinskia at gcc dot gnu.org
2023-02-03 23:15 ` vmakarov at gcc dot gnu.org
2023-02-07 14:05 ` cvs-commit at gcc dot gnu.org
2023-02-08 22:30 ` hjl.tools at gmail dot com
2023-02-09 21:48 ` cvs-commit at gcc dot gnu.org
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).