public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/96779] New: Failure to optimize comparison of negative version of self
@ 2020-08-25 12:03 gabravier at gmail dot com
2020-08-25 12:14 ` [Bug tree-optimization/96779] " rguenth at gcc dot gnu.org
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: gabravier at gmail dot com @ 2020-08-25 12:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96779
Bug ID: 96779
Summary: Failure to optimize comparison of negative version of
self
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(int a)
{
return -a == a;
}
This can be optimized to `return !a;`. This transformation is done by LLVM, but
not by GCC.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/96779] Failure to optimize comparison of negative version of self
2020-08-25 12:03 [Bug tree-optimization/96779] New: Failure to optimize comparison of negative version of self gabravier at gmail dot com
@ 2020-08-25 12:14 ` rguenth at gcc dot gnu.org
2021-07-23 4:02 ` pinskia at gcc dot gnu.org
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-08-25 12:14 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96779
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2020-08-25
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/96779] Failure to optimize comparison of negative version of self
2020-08-25 12:03 [Bug tree-optimization/96779] New: Failure to optimize comparison of negative version of self gabravier at gmail dot com
2020-08-25 12:14 ` [Bug tree-optimization/96779] " rguenth at gcc dot gnu.org
@ 2021-07-23 4:02 ` pinskia at gcc dot gnu.org
2021-07-27 20:10 ` pinskia at gcc dot gnu.org
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-23 4:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96779
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
Keywords| |easyhack
Assignee|unassigned at gcc dot gnu.org |pinskia at gcc dot gnu.org
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This is simple, I will take.
(for cmp (eq ne)
(simplify
(cmp:c @0 (negate @0))
(if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0)))
(cmp:c @0 { build_zero_cst (TREE_TYPE(@0)); })))))
Should be enough.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/96779] Failure to optimize comparison of negative version of self
2020-08-25 12:03 [Bug tree-optimization/96779] New: Failure to optimize comparison of negative version of self gabravier at gmail dot com
2020-08-25 12:14 ` [Bug tree-optimization/96779] " rguenth at gcc dot gnu.org
2021-07-23 4:02 ` pinskia at gcc dot gnu.org
@ 2021-07-27 20:10 ` pinskia at gcc dot gnu.org
2021-11-10 19:50 ` navidrahimi at microsoft dot com
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-27 20:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96779
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #2)
> This is simple, I will take.
> (for cmp (eq ne)
> (simplify
> (cmp:c @0 (negate @0))
> (if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0)))
> (cmp:c @0 { build_zero_cst (TREE_TYPE(@0)); })))))
>
> Should be enough.
But it is wrong for wrapping types.
For wrapping types:
-a == a -> (a << 1) == a or (a + a) == 0
But this is worse on targets which have a pattern for -a CMP a (hint aarch64).
So for wrapping types keep the -a == a is the best I think.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/96779] Failure to optimize comparison of negative version of self
2020-08-25 12:03 [Bug tree-optimization/96779] New: Failure to optimize comparison of negative version of self gabravier at gmail dot com
` (2 preceding siblings ...)
2021-07-27 20:10 ` pinskia at gcc dot gnu.org
@ 2021-11-10 19:50 ` navidrahimi at microsoft dot com
2021-11-10 20:18 ` navidrahimi at microsoft dot com
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: navidrahimi at microsoft dot com @ 2021-11-10 19:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96779
navidrahimi <navidrahimi at microsoft dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |navidrahimi at microsoft dot com
--- Comment #4 from navidrahimi <navidrahimi at microsoft dot com> ---
Hi Andrew,
I just used your code and added a check to check whether the type is wrapping
type:
(for cmp (eq ne)
(simplify
(cmp:c @0 (negate @0))
(if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0))
&& !TYPE_OVERFLOW_WRAPS (type))
(cmp:c @0 { build_zero_cst (TREE_TYPE(@0)); })))))
This should work.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/96779] Failure to optimize comparison of negative version of self
2020-08-25 12:03 [Bug tree-optimization/96779] New: Failure to optimize comparison of negative version of self gabravier at gmail dot com
` (3 preceding siblings ...)
2021-11-10 19:50 ` navidrahimi at microsoft dot com
@ 2021-11-10 20:18 ` navidrahimi at microsoft dot com
2021-11-23 0:48 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: navidrahimi at microsoft dot com @ 2021-11-10 20:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96779
--- Comment #5 from navidrahimi <navidrahimi at microsoft dot com> ---
And this is the behavior of different compilers for this optimization:
https://compiler-explorer.com/z/ahdEzxxTv
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/96779] Failure to optimize comparison of negative version of self
2020-08-25 12:03 [Bug tree-optimization/96779] New: Failure to optimize comparison of negative version of self gabravier at gmail dot com
` (4 preceding siblings ...)
2021-11-10 20:18 ` navidrahimi at microsoft dot com
@ 2021-11-23 0:48 ` cvs-commit at gcc dot gnu.org
2021-11-23 0:49 ` law at gcc dot gnu.org
2022-01-10 11:51 ` pinskia at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-11-23 0:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96779
--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jeff Law <law@gcc.gnu.org>:
https://gcc.gnu.org/g:e888bea2384a0d8d29a6545c4f57f41cb49df0a6
commit r12-5458-ge888bea2384a0d8d29a6545c4f57f41cb49df0a6
Author: Navid Rahimi <navidrahimi@microsoft.com>
Date: Mon Nov 22 19:46:17 2021 -0500
Re: [PATCH] PR tree-optimization/96779 Adding a missing pattern to match.pd
PR tree-optimization/96779
gcc/
* match.pd (-x == x) -> (x == 0): New optimization.
gcc/testsuite
* gcc.dg/tree-ssa/pr96779.c: Testcase for this optimization.
* gcc.dg/tree-ssa/pr96779-disabled.c: Testcase for this
optimization
when -fwrapv passed.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/96779] Failure to optimize comparison of negative version of self
2020-08-25 12:03 [Bug tree-optimization/96779] New: Failure to optimize comparison of negative version of self gabravier at gmail dot com
` (5 preceding siblings ...)
2021-11-23 0:48 ` cvs-commit at gcc dot gnu.org
@ 2021-11-23 0:49 ` law at gcc dot gnu.org
2022-01-10 11:51 ` pinskia at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: law at gcc dot gnu.org @ 2021-11-23 0:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96779
Jeffrey A. Law <law at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
CC| |law at gcc dot gnu.org
Status|ASSIGNED |RESOLVED
--- Comment #7 from Jeffrey A. Law <law at gcc dot gnu.org> ---
Should be fixed by Navid's patch on the trunk.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/96779] Failure to optimize comparison of negative version of self
2020-08-25 12:03 [Bug tree-optimization/96779] New: Failure to optimize comparison of negative version of self gabravier at gmail dot com
` (6 preceding siblings ...)
2021-11-23 0:49 ` law at gcc dot gnu.org
@ 2022-01-10 11:51 ` pinskia at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-10 11:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96779
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |12.0
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2022-01-10 11:51 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-25 12:03 [Bug tree-optimization/96779] New: Failure to optimize comparison of negative version of self gabravier at gmail dot com
2020-08-25 12:14 ` [Bug tree-optimization/96779] " rguenth at gcc dot gnu.org
2021-07-23 4:02 ` pinskia at gcc dot gnu.org
2021-07-27 20:10 ` pinskia at gcc dot gnu.org
2021-11-10 19:50 ` navidrahimi at microsoft dot com
2021-11-10 20:18 ` navidrahimi at microsoft dot com
2021-11-23 0:48 ` cvs-commit at gcc dot gnu.org
2021-11-23 0:49 ` law at gcc dot gnu.org
2022-01-10 11:51 ` 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).