public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/109845] New: Addition overflow/carry flag unnecessarily put in a temporary register
@ 2023-05-13 18:32 chfast at gmail dot com
2023-05-13 18:39 ` [Bug rtl-optimization/109845] " pinskia at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: chfast at gmail dot com @ 2023-05-13 18:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109845
Bug ID: 109845
Summary: Addition overflow/carry flag unnecessarily put in a
temporary register
Product: gcc
Version: 13.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: rtl-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: chfast at gmail dot com
Target Milestone: ---
When we have an addition and an overflow check and the overflow flag is
combined with some other condition the codegen may generate variant when the
overflow flag is temporary register.
unsigned s = y + z;
_Bool ov = s < y;
if (x || ov)
return;
This produces
add esi, edx
setc al
test edi, edi
jne .L1
test eax, eax
jne .L1
while it could be
add esi, edx
jc .L6
test edi, edi
jne .L6
There are easy workaround to the C code which make the assembly optimal:
1. Change the order of checks
if (ov || x)
2. Split if into two
if (x)
return;
if (ov)
return;
https://godbolt.org/z/rxsrnhPdc
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug rtl-optimization/109845] Addition overflow/carry flag unnecessarily put in a temporary register
2023-05-13 18:32 [Bug rtl-optimization/109845] New: Addition overflow/carry flag unnecessarily put in a temporary register chfast at gmail dot com
@ 2023-05-13 18:39 ` pinskia at gcc dot gnu.org
2023-05-13 18:45 ` [Bug middle-end/109845] " pinskia at gcc dot gnu.org
2023-05-15 6:52 ` rguenth at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-13 18:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109845
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 55077
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55077&action=edit
full testcase
Next time please attach the full compilable testcase or paste it inline rather
than just including a godbolt link.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug middle-end/109845] Addition overflow/carry flag unnecessarily put in a temporary register
2023-05-13 18:32 [Bug rtl-optimization/109845] New: Addition overflow/carry flag unnecessarily put in a temporary register chfast at gmail dot com
2023-05-13 18:39 ` [Bug rtl-optimization/109845] " pinskia at gcc dot gnu.org
@ 2023-05-13 18:45 ` pinskia at gcc dot gnu.org
2023-05-15 6:52 ` rguenth at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-13 18:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109845
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2023-05-13
Status|UNCONFIRMED |NEW
Severity|normal |enhancement
Component|rtl-optimization |middle-end
Keywords| |missed-optimization
Ever confirmed|0 |1
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
So the difference between good1 and bad1 at the gimple level is the order of
operands of the bit_ior:
good1:
ov_8 = _13 != 0;
_9 = x_2(D) != 0;
_10 = ov_8 | _9;
if (_10 != 0)
bad1:
ov_7 = _13 != 0;
_1 = x_8(D) != 0;
_2 = _1 | ov_7;
if (_2 != 0)
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug middle-end/109845] Addition overflow/carry flag unnecessarily put in a temporary register
2023-05-13 18:32 [Bug rtl-optimization/109845] New: Addition overflow/carry flag unnecessarily put in a temporary register chfast at gmail dot com
2023-05-13 18:39 ` [Bug rtl-optimization/109845] " pinskia at gcc dot gnu.org
2023-05-13 18:45 ` [Bug middle-end/109845] " pinskia at gcc dot gnu.org
@ 2023-05-15 6:52 ` rguenth at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-05-15 6:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109845
--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
Yup, bad luck for later RTL optimization. It might help to perform jump
expansions decision to go for jump or straight-line code earlier on GIMPLE (and
stick to that).
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-05-15 6:52 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-13 18:32 [Bug rtl-optimization/109845] New: Addition overflow/carry flag unnecessarily put in a temporary register chfast at gmail dot com
2023-05-13 18:39 ` [Bug rtl-optimization/109845] " pinskia at gcc dot gnu.org
2023-05-13 18:45 ` [Bug middle-end/109845] " pinskia at gcc dot gnu.org
2023-05-15 6:52 ` rguenth 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).