public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/96674] New: Failure to optimize combination of comparisons to dec+compare
@ 2020-08-18 10:30 gabravier at gmail dot com
2020-08-25 10:45 ` [Bug tree-optimization/96674] " rguenth at gcc dot gnu.org
` (13 more replies)
0 siblings, 14 replies; 15+ messages in thread
From: gabravier at gmail dot com @ 2020-08-18 10:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96674
Bug ID: 96674
Summary: Failure to optimize combination of comparisons to
dec+compare
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: gabravier at gmail dot com
Target Milestone: ---
bool f(unsigned a, unsigned b)
{
return (b == 0) | (a < b);
}
This can be optimized to `return a <= (b - 1);`. This transformation is done by
LLVM, but not by GCC.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug tree-optimization/96674] Failure to optimize combination of comparisons to dec+compare
2020-08-18 10:30 [Bug tree-optimization/96674] New: Failure to optimize combination of comparisons to dec+compare gabravier at gmail dot com
@ 2020-08-25 10:45 ` rguenth at gcc dot gnu.org
2020-08-31 0:58 ` pinskia at gcc dot gnu.org
` (12 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-08-25 10:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96674
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
Last reconfirmed| |2020-08-25
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug tree-optimization/96674] Failure to optimize combination of comparisons to dec+compare
2020-08-18 10:30 [Bug tree-optimization/96674] New: Failure to optimize combination of comparisons to dec+compare gabravier at gmail dot com
2020-08-25 10:45 ` [Bug tree-optimization/96674] " rguenth at gcc dot gnu.org
@ 2020-08-31 0:58 ` pinskia at gcc dot gnu.org
2021-01-11 22:53 ` erozen at microsoft dot com
` (11 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-08-31 0:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96674
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
Keywords| |easyhack
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug tree-optimization/96674] Failure to optimize combination of comparisons to dec+compare
2020-08-18 10:30 [Bug tree-optimization/96674] New: Failure to optimize combination of comparisons to dec+compare gabravier at gmail dot com
2020-08-25 10:45 ` [Bug tree-optimization/96674] " rguenth at gcc dot gnu.org
2020-08-31 0:58 ` pinskia at gcc dot gnu.org
@ 2021-01-11 22:53 ` erozen at microsoft dot com
2021-01-12 11:52 ` gabravier at gmail dot com
` (10 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: erozen at microsoft dot com @ 2021-01-11 22:53 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96674
Eugene Rozenfeld <erozen at microsoft dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |erozen at microsoft dot com
--- Comment #1 from Eugene Rozenfeld <erozen at microsoft dot com> ---
Created attachment 49940
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49940&action=edit
[PATCH] Optimize combination of comparisons to dec+compare
The patch has been approved by Richard Biener.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug tree-optimization/96674] Failure to optimize combination of comparisons to dec+compare
2020-08-18 10:30 [Bug tree-optimization/96674] New: Failure to optimize combination of comparisons to dec+compare gabravier at gmail dot com
` (2 preceding siblings ...)
2021-01-11 22:53 ` erozen at microsoft dot com
@ 2021-01-12 11:52 ` gabravier at gmail dot com
2021-01-12 23:12 ` erozen at microsoft dot com
` (9 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: gabravier at gmail dot com @ 2021-01-12 11:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96674
--- Comment #2 from Gabriel Ravier <gabravier at gmail dot com> ---
Isn't __attribute__((noipa)) usually used instead of __attribute__((noinline))
?
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug tree-optimization/96674] Failure to optimize combination of comparisons to dec+compare
2020-08-18 10:30 [Bug tree-optimization/96674] New: Failure to optimize combination of comparisons to dec+compare gabravier at gmail dot com
` (3 preceding siblings ...)
2021-01-12 11:52 ` gabravier at gmail dot com
@ 2021-01-12 23:12 ` erozen at microsoft dot com
2021-01-12 23:34 ` gabravier at gmail dot com
` (8 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: erozen at microsoft dot com @ 2021-01-12 23:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96674
--- Comment #3 from Eugene Rozenfeld <erozen at microsoft dot com> ---
Both are used but it looks like __attribute__((noinline)) is used more
frequently.
Under gcc/testsuite there are 1537 instances of __attribute__((noipa)) and 3794
instances of __attribute__((noinline)).
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug tree-optimization/96674] Failure to optimize combination of comparisons to dec+compare
2020-08-18 10:30 [Bug tree-optimization/96674] New: Failure to optimize combination of comparisons to dec+compare gabravier at gmail dot com
` (4 preceding siblings ...)
2021-01-12 23:12 ` erozen at microsoft dot com
@ 2021-01-12 23:34 ` gabravier at gmail dot com
2021-01-12 23:45 ` jakub at gcc dot gnu.org
` (7 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: gabravier at gmail dot com @ 2021-01-12 23:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96674
--- Comment #4 from Gabriel Ravier <gabravier at gmail dot com> ---
I'd assume those are for older test cases: __attribute__((noipa)) makes more
sense (at least to me) considering it's made specifically to prevent
inter-procedural optimization (which __attribute__((noinline)) does not, afaik)
which is helpful for testing specific optimizations on specific functions and
seeing whether the optimizations make those functions non-functional without
potentially having problems with inter-procedural optimization doing stuff like
constant-propagation or anything that could interfere with the proper testing
of a specific optimization.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug tree-optimization/96674] Failure to optimize combination of comparisons to dec+compare
2020-08-18 10:30 [Bug tree-optimization/96674] New: Failure to optimize combination of comparisons to dec+compare gabravier at gmail dot com
` (5 preceding siblings ...)
2021-01-12 23:34 ` gabravier at gmail dot com
@ 2021-01-12 23:45 ` jakub at gcc dot gnu.org
2021-01-14 21:06 ` erozen at microsoft dot com
` (6 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-01-12 23:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96674
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
/* x < y || x == XXX_MIN --> x <= y - 1 */
(simplify
(bit_ior (eq @1 min_value) (lt @0 @1))
(if (INTEGRAL_TYPE_P (TREE_TYPE (@1))
&& TYPE_OVERFLOW_WRAPS (TREE_TYPE (@1)))
(le @0 (minus @1 { build_int_cst (TREE_TYPE (@1), 1); }))))
The comment doesn't match what the simplification implements (x == XXX_MIN
should be y == XXX_MIN).
Furthermore, bit_ior is commutative and for the optimization no specific order
is needed, so probably bit_ior:c is needed. Also, the optimization doesn't
seem to be worth if either eq or lt has multiple uses, so both should have :s
suffixes. When x < y || y == min can be simplified into x <= y - 1, can't
its negation, i.e. x >= y && y != min be simplified into x > y - 1 ?
And agree on the noipa attribute, most of the tests you're citing just predate
the noipa attribute. We had noinline for many years, later added noclone and
have been using noinline, noclone and when we started adding further IPA
optimizations, noipa has been added.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug tree-optimization/96674] Failure to optimize combination of comparisons to dec+compare
2020-08-18 10:30 [Bug tree-optimization/96674] New: Failure to optimize combination of comparisons to dec+compare gabravier at gmail dot com
` (6 preceding siblings ...)
2021-01-12 23:45 ` jakub at gcc dot gnu.org
@ 2021-01-14 21:06 ` erozen at microsoft dot com
2021-01-14 21:07 ` erozen at microsoft dot com
` (5 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: erozen at microsoft dot com @ 2021-01-14 21:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96674
Eugene Rozenfeld <erozen at microsoft dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Attachment #49940|0 |1
is obsolete| |
--- Comment #6 from Eugene Rozenfeld <erozen at microsoft dot com> ---
Created attachment 49969
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49969&action=edit
Optimize combination of comparisons to dec+compare
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug tree-optimization/96674] Failure to optimize combination of comparisons to dec+compare
2020-08-18 10:30 [Bug tree-optimization/96674] New: Failure to optimize combination of comparisons to dec+compare gabravier at gmail dot com
` (7 preceding siblings ...)
2021-01-14 21:06 ` erozen at microsoft dot com
@ 2021-01-14 21:07 ` erozen at microsoft dot com
2021-01-14 21:30 ` ubizjak at gmail dot com
` (4 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: erozen at microsoft dot com @ 2021-01-14 21:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96674
--- Comment #7 from Eugene Rozenfeld <erozen at microsoft dot com> ---
Thank you for the feedback, Gabriel and Jakub. I re-worked the patch based on
your suggestions. I attached the new patch and also sent it to gcc-patches.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug tree-optimization/96674] Failure to optimize combination of comparisons to dec+compare
2020-08-18 10:30 [Bug tree-optimization/96674] New: Failure to optimize combination of comparisons to dec+compare gabravier at gmail dot com
` (8 preceding siblings ...)
2021-01-14 21:07 ` erozen at microsoft dot com
@ 2021-01-14 21:30 ` ubizjak at gmail dot com
2021-01-15 0:32 ` erozen at microsoft dot com
` (3 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: ubizjak at gmail dot com @ 2021-01-14 21:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96674
--- Comment #8 from Uroš Bizjak <ubizjak at gmail dot com> ---
Comment on attachment 49969
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49969
Optimize combination of comparisons to dec+compare
>+/* y == XXX_MIN || x < y --> x <= y - 1 */
Can we use TYPE_MIN instead of XXX_MIN?
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug tree-optimization/96674] Failure to optimize combination of comparisons to dec+compare
2020-08-18 10:30 [Bug tree-optimization/96674] New: Failure to optimize combination of comparisons to dec+compare gabravier at gmail dot com
` (9 preceding siblings ...)
2021-01-14 21:30 ` ubizjak at gmail dot com
@ 2021-01-15 0:32 ` erozen at microsoft dot com
2021-01-20 15:32 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: erozen at microsoft dot com @ 2021-01-15 0:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96674
--- Comment #9 from Eugene Rozenfeld <erozen at microsoft dot com> ---
I used XXX_MIN for consistency with comments on other patterns. If TYPE_MIN is
preferable, the change should be made in all of those comments as well.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug tree-optimization/96674] Failure to optimize combination of comparisons to dec+compare
2020-08-18 10:30 [Bug tree-optimization/96674] New: Failure to optimize combination of comparisons to dec+compare gabravier at gmail dot com
` (10 preceding siblings ...)
2021-01-15 0:32 ` erozen at microsoft dot com
@ 2021-01-20 15:32 ` cvs-commit at gcc dot gnu.org
2021-06-02 18:59 ` law at gcc dot gnu.org
2021-09-17 6:44 ` pinskia at gcc dot gnu.org
13 siblings, 0 replies; 15+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-01-20 15:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96674
--- Comment #10 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:
https://gcc.gnu.org/g:49e8c14ef6f1f968602a04c8499a672182590e87
commit r11-6817-g49e8c14ef6f1f968602a04c8499a672182590e87
Author: Eugene Rozenfeld <erozen@microsoft.com>
Date: Wed Dec 9 16:44:25 2020 -0800
Optimize combination of comparisons to dec+compare
This patch adds patterns for optimizing
x < y || y == XXX_MIN to x <= y-1
x >= y && y != XXX_MIN to x > y-1
if y is an integer with TYPE_OVERFLOW_WRAPS.
This fixes pr96674.
Tested on x86_64-pc-linux-gnu.
For this function
bool f(unsigned a, unsigned b)
{
return (b == 0) | (a < b);
}
the code without the patch is
test esi,esi
sete al
cmp esi,edi
seta dl
or eax,edx
ret
the code with the patch is
sub esi,0x1
cmp esi,edi
setae al
ret
PR tree-optimization/96674
gcc/
* match.pd: New patterns: x < y || y == XXX_MIN --> x <= y - 1
x >= y && y != XXX_MIN --> x > y - 1
gcc/testsuite
* gcc.dg/pr96674.c: New tests.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug tree-optimization/96674] Failure to optimize combination of comparisons to dec+compare
2020-08-18 10:30 [Bug tree-optimization/96674] New: Failure to optimize combination of comparisons to dec+compare gabravier at gmail dot com
` (11 preceding siblings ...)
2021-01-20 15:32 ` cvs-commit at gcc dot gnu.org
@ 2021-06-02 18:59 ` law at gcc dot gnu.org
2021-09-17 6:44 ` pinskia at gcc dot gnu.org
13 siblings, 0 replies; 15+ messages in thread
From: law at gcc dot gnu.org @ 2021-06-02 18:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96674
Jeffrey A. Law <law at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
CC| |law at gcc dot gnu.org
Resolution|--- |FIXED
--- Comment #11 from Jeffrey A. Law <law at gcc dot gnu.org> ---
Resolved by Eugene's patch on the trunk.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug tree-optimization/96674] Failure to optimize combination of comparisons to dec+compare
2020-08-18 10:30 [Bug tree-optimization/96674] New: Failure to optimize combination of comparisons to dec+compare gabravier at gmail dot com
` (12 preceding siblings ...)
2021-06-02 18:59 ` law at gcc dot gnu.org
@ 2021-09-17 6:44 ` pinskia at gcc dot gnu.org
13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-17 6:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96674
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |11.0
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2021-09-17 6:44 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-18 10:30 [Bug tree-optimization/96674] New: Failure to optimize combination of comparisons to dec+compare gabravier at gmail dot com
2020-08-25 10:45 ` [Bug tree-optimization/96674] " rguenth at gcc dot gnu.org
2020-08-31 0:58 ` pinskia at gcc dot gnu.org
2021-01-11 22:53 ` erozen at microsoft dot com
2021-01-12 11:52 ` gabravier at gmail dot com
2021-01-12 23:12 ` erozen at microsoft dot com
2021-01-12 23:34 ` gabravier at gmail dot com
2021-01-12 23:45 ` jakub at gcc dot gnu.org
2021-01-14 21:06 ` erozen at microsoft dot com
2021-01-14 21:07 ` erozen at microsoft dot com
2021-01-14 21:30 ` ubizjak at gmail dot com
2021-01-15 0:32 ` erozen at microsoft dot com
2021-01-20 15:32 ` cvs-commit at gcc dot gnu.org
2021-06-02 18:59 ` law at gcc dot gnu.org
2021-09-17 6:44 ` pinskia 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).