public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/113268] New: (i + (i + 1) * CST) AND (i + i * CST + 1 * CST) not folded the same way
@ 2024-01-08 10:35 denis.campredon at gmail dot com
2024-01-09 8:23 ` [Bug tree-optimization/113268] " rguenth at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: denis.campredon at gmail dot com @ 2024-01-08 10:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113268
Bug ID: 113268
Summary: (i + (i + 1) * CST) AND (i + i * CST + 1 * CST) not
folded the same way
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: denis.campredon at gmail dot com
Target Milestone: ---
The two following functions should produce the same assembly with optimizations
enabled.
This lead, for exemple, to missed optimization with -Oz
---------------
#define CST 36
int foo(int i)
{
return i + (i + 1) * CST;
}
int bar(int i)
{
return i + i * CST + 1 * CST;
}
---------------
foo:
lea eax, [rdi+1]
imul eax, eax, 36
add eax, edi
ret
bar:
imul eax, edi, 37
add eax, 36
ret
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug tree-optimization/113268] (i + (i + 1) * CST) AND (i + i * CST + 1 * CST) not folded the same way
2024-01-08 10:35 [Bug tree-optimization/113268] New: (i + (i + 1) * CST) AND (i + i * CST + 1 * CST) not folded the same way denis.campredon at gmail dot com
@ 2024-01-09 8:23 ` rguenth at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-01-09 8:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113268
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Keywords| |missed-optimization
Status|UNCONFIRMED |NEW
Last reconfirmed| |2024-01-09
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
(i + 1) * CST and i * CST + 1 * CST can have different overflow behavior,
so (i + 1) * CST cannot be turned into i * CST + CST unconditionally.
The reverse transform would be valid through I think.
RTL or GIMPLE with -fwrapv should be able to handle both the same. There's
still the old idea of making late GIMPLE effectively -fwrapv, the same as RTL
behaves.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-01-09 8:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-08 10:35 [Bug tree-optimization/113268] New: (i + (i + 1) * CST) AND (i + i * CST + 1 * CST) not folded the same way denis.campredon at gmail dot com
2024-01-09 8:23 ` [Bug tree-optimization/113268] " 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).