public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/104992] New: [missed optimization] x / y * y == x not optimized to x % y == 0
@ 2022-03-20 15:19 tilkax at gmail dot com
2022-03-20 20:25 ` [Bug tree-optimization/104992] " pinskia at gcc dot gnu.org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: tilkax at gmail dot com @ 2022-03-20 15:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104992
Bug ID: 104992
Summary: [missed optimization] x / y * y == x not optimized to
x % y == 0
Product: gcc
Version: 11.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: tilkax at gmail dot com
Target Milestone: ---
This is especially helpful for constant y because checking
division-by-a-constant remainders against zero allows further optimization.
Repro case:
unsigned foo(unsigned x, unsigned y)
{
return x / y * y == x;
}
GCC -O3:
mov eax, edi
xor edx, edx
div esi
mov eax, edi
sub eax, edx
cmp eax, edi
sete al
movzx eax, al
ret
Clang -O3:
mov eax, edi
xor edx, edx
div esi
xor eax, eax
test edx, edx
sete al
ret
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/104992] [missed optimization] x / y * y == x not optimized to x % y == 0
2022-03-20 15:19 [Bug tree-optimization/104992] New: [missed optimization] x / y * y == x not optimized to x % y == 0 tilkax at gmail dot com
@ 2022-03-20 20:25 ` pinskia at gcc dot gnu.org
2022-03-21 9:37 ` rguenth at gcc dot gnu.org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-03-20 20:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104992
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
Keywords| |missed-optimization
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/104992] [missed optimization] x / y * y == x not optimized to x % y == 0
2022-03-20 15:19 [Bug tree-optimization/104992] New: [missed optimization] x / y * y == x not optimized to x % y == 0 tilkax at gmail dot com
2022-03-20 20:25 ` [Bug tree-optimization/104992] " pinskia at gcc dot gnu.org
@ 2022-03-21 9:37 ` rguenth at gcc dot gnu.org
2022-08-01 13:24 ` cvs-commit at gcc dot gnu.org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-03-21 9:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104992
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2022-03-21
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/104992] [missed optimization] x / y * y == x not optimized to x % y == 0
2022-03-20 15:19 [Bug tree-optimization/104992] New: [missed optimization] x / y * y == x not optimized to x % y == 0 tilkax at gmail dot com
2022-03-20 20:25 ` [Bug tree-optimization/104992] " pinskia at gcc dot gnu.org
2022-03-21 9:37 ` rguenth at gcc dot gnu.org
@ 2022-08-01 13:24 ` cvs-commit at gcc dot gnu.org
2022-08-03 16:00 ` seurer at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-08-01 13:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104992
--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Sam Feifer <sfeifer@gcc.gnu.org>:
https://gcc.gnu.org/g:388fbbd895e72669909173c3003ae65c6483a3c2
commit r13-1916-g388fbbd895e72669909173c3003ae65c6483a3c2
Author: Sam Feifer <sfeifer@redhat.com>
Date: Fri Jul 29 09:44:48 2022 -0400
match.pd: Add new division pattern [PR104992]
This patch fixes a missed optimization in match.pd. It takes the pattern,
x / y * y == x, and optimizes it to x % y == 0. This produces fewer
instructions. This simplification does not happen for complex types.
This patch also adds tests for the optimization rule.
Bootstrapped/regtested on x86_64-pc-linux-gnu.
PR tree-optimization/104992
gcc/ChangeLog:
* match.pd (x / y * y == x): New simplification.
gcc/testsuite/ChangeLog:
* g++.dg/pr104992-1.C: New test.
* gcc.dg/pr104992.c: New test.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/104992] [missed optimization] x / y * y == x not optimized to x % y == 0
2022-03-20 15:19 [Bug tree-optimization/104992] New: [missed optimization] x / y * y == x not optimized to x % y == 0 tilkax at gmail dot com
` (2 preceding siblings ...)
2022-08-01 13:24 ` cvs-commit at gcc dot gnu.org
@ 2022-08-03 16:00 ` seurer at gcc dot gnu.org
2022-08-11 8:29 ` cvs-commit at gcc dot gnu.org
2024-01-23 12:12 ` xry111 at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: seurer at gcc dot gnu.org @ 2022-08-03 16:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104992
seurer at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |seurer at gcc dot gnu.org
--- Comment #3 from seurer at gcc dot gnu.org ---
The fix for this causes an issue on power 10. See PR106516
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/104992] [missed optimization] x / y * y == x not optimized to x % y == 0
2022-03-20 15:19 [Bug tree-optimization/104992] New: [missed optimization] x / y * y == x not optimized to x % y == 0 tilkax at gmail dot com
` (3 preceding siblings ...)
2022-08-03 16:00 ` seurer at gcc dot gnu.org
@ 2022-08-11 8:29 ` cvs-commit at gcc dot gnu.org
2024-01-23 12:12 ` xry111 at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-08-11 8:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104992
--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:
https://gcc.gnu.org/g:8e69f2a6e91b7a01619dfd3b0788bfda4ad28941
commit r13-2018-g8e69f2a6e91b7a01619dfd3b0788bfda4ad28941
Author: Jakub Jelinek <jakub@redhat.com>
Date: Thu Aug 11 10:26:32 2022 +0200
testsuite: Fix up pr104992* tests on i686-linux [PR104992]
These 2 tests were FAILing on i686-linux or e.g. with
--target_board=unix/-m32/-mno-sse on x86_64-linux due to
-Wpsabi warnings and also because dg-options in the latter
test has been ignored due to missing space, so even -O2
wasn't passed at all.
2022-08-11 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/104992
* gcc.dg/pr104992.c: Add -Wno-psabi to dg-options.
* g++.dg/pr104992-1.C: Likewise. Add space between " and } in
dg-options.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/104992] [missed optimization] x / y * y == x not optimized to x % y == 0
2022-03-20 15:19 [Bug tree-optimization/104992] New: [missed optimization] x / y * y == x not optimized to x % y == 0 tilkax at gmail dot com
` (4 preceding siblings ...)
2022-08-11 8:29 ` cvs-commit at gcc dot gnu.org
@ 2024-01-23 12:12 ` xry111 at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: xry111 at gcc dot gnu.org @ 2024-01-23 12:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104992
Xi Ruoyao <xry111 at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |xry111 at gcc dot gnu.org
--- Comment #5 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
Hmm, shouldn't we close this as fixed now?
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-01-23 12:12 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-20 15:19 [Bug tree-optimization/104992] New: [missed optimization] x / y * y == x not optimized to x % y == 0 tilkax at gmail dot com
2022-03-20 20:25 ` [Bug tree-optimization/104992] " pinskia at gcc dot gnu.org
2022-03-21 9:37 ` rguenth at gcc dot gnu.org
2022-08-01 13:24 ` cvs-commit at gcc dot gnu.org
2022-08-03 16:00 ` seurer at gcc dot gnu.org
2022-08-11 8:29 ` cvs-commit at gcc dot gnu.org
2024-01-23 12:12 ` xry111 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).