public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/111957] New: `a ? abs(a) : 0` is not simplified to just abs(a)
@ 2023-10-24 16:15 pinskia at gcc dot gnu.org
2023-10-24 16:15 ` [Bug tree-optimization/111957] " pinskia at gcc dot gnu.org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-24 16:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111957
Bug ID: 111957
Summary: `a ? abs(a) : 0` is not simplified to just abs(a)
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: enhancement
Priority: P3
Component: tree-optimization
Assignee: pinskia at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
Take:
```
int f(int a)
{
if (a)
return a > 0 ? a : -a;
return 0;
}
```
This should just simplify to ` return a > 0 ? a : -a;` or rather `return
abs(a);`
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/111957] `a ? abs(a) : 0` is not simplified to just abs(a)
2023-10-24 16:15 [Bug tree-optimization/111957] New: `a ? abs(a) : 0` is not simplified to just abs(a) pinskia at gcc dot gnu.org
@ 2023-10-24 16:15 ` pinskia at gcc dot gnu.org
2023-10-24 22:37 ` pinskia at gcc dot gnu.org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-24 16:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111957
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2023-10-24
Status|UNCONFIRMED |ASSIGNED
Ever confirmed|0 |1
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/111957] `a ? abs(a) : 0` is not simplified to just abs(a)
2023-10-24 16:15 [Bug tree-optimization/111957] New: `a ? abs(a) : 0` is not simplified to just abs(a) pinskia at gcc dot gnu.org
2023-10-24 16:15 ` [Bug tree-optimization/111957] " pinskia at gcc dot gnu.org
@ 2023-10-24 22:37 ` pinskia at gcc dot gnu.org
2023-10-24 23:35 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-24 22:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111957
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
We already have patterns for -a and ~a even:
/* X != C1 ? -X : C2 simplifies to -X when -C1 == C2. */
/* X != C1 ? ~X : C2 simplifies to ~X when ~C1 == C2. */
I will add one to handle abs too.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/111957] `a ? abs(a) : 0` is not simplified to just abs(a)
2023-10-24 16:15 [Bug tree-optimization/111957] New: `a ? abs(a) : 0` is not simplified to just abs(a) pinskia at gcc dot gnu.org
2023-10-24 16:15 ` [Bug tree-optimization/111957] " pinskia at gcc dot gnu.org
2023-10-24 22:37 ` pinskia at gcc dot gnu.org
@ 2023-10-24 23:35 ` pinskia at gcc dot gnu.org
2023-10-25 3:43 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-24 23:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111957
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 56196
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56196&action=edit
patch which I am testing
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/111957] `a ? abs(a) : 0` is not simplified to just abs(a)
2023-10-24 16:15 [Bug tree-optimization/111957] New: `a ? abs(a) : 0` is not simplified to just abs(a) pinskia at gcc dot gnu.org
` (2 preceding siblings ...)
2023-10-24 23:35 ` pinskia at gcc dot gnu.org
@ 2023-10-25 3:43 ` pinskia at gcc dot gnu.org
2023-10-26 18:58 ` cvs-commit at gcc dot gnu.org
2023-10-26 18:58 ` pinskia at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-25 3:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111957
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
URL| |https://gcc.gnu.org/piperma
| |il/gcc-patches/2023-October
| |/634204.html
Keywords| |patch
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Patch posted:
https://gcc.gnu.org/pipermail/gcc-patches/2023-October/634204.html
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/111957] `a ? abs(a) : 0` is not simplified to just abs(a)
2023-10-24 16:15 [Bug tree-optimization/111957] New: `a ? abs(a) : 0` is not simplified to just abs(a) pinskia at gcc dot gnu.org
` (3 preceding siblings ...)
2023-10-25 3:43 ` pinskia at gcc dot gnu.org
@ 2023-10-26 18:58 ` cvs-commit at gcc dot gnu.org
2023-10-26 18:58 ` pinskia at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-10-26 18:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111957
--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Andrew Pinski <pinskia@gcc.gnu.org>:
https://gcc.gnu.org/g:662655e22dddf5392d9aa67fce45beee980e5454
commit r14-4955-g662655e22dddf5392d9aa67fce45beee980e5454
Author: Andrew Pinski <pinskia@gmail.com>
Date: Tue Oct 24 23:13:18 2023 +0000
match: Simplify `a != C1 ? abs(a) : C2` when C2 == abs(C1) [PR111957]
This adds a match pattern for `a != C1 ? abs(a) : C2` which gets simplified
to `abs(a)`. if C1 was originally *_MIN then change it over to use absu
instead
of abs.
Bootstrapped and tested on x86_64-linux-gnu with no regressions.
PR tree-optimization/111957
gcc/ChangeLog:
* match.pd (`a != C1 ? abs(a) : C2`): New pattern.
gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/phi-opt-40.c: New test.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/111957] `a ? abs(a) : 0` is not simplified to just abs(a)
2023-10-24 16:15 [Bug tree-optimization/111957] New: `a ? abs(a) : 0` is not simplified to just abs(a) pinskia at gcc dot gnu.org
` (4 preceding siblings ...)
2023-10-26 18:58 ` cvs-commit at gcc dot gnu.org
@ 2023-10-26 18:58 ` pinskia at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-26 18:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111957
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
Target Milestone|--- |14.0
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
fixed.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-10-26 18:58 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-24 16:15 [Bug tree-optimization/111957] New: `a ? abs(a) : 0` is not simplified to just abs(a) pinskia at gcc dot gnu.org
2023-10-24 16:15 ` [Bug tree-optimization/111957] " pinskia at gcc dot gnu.org
2023-10-24 22:37 ` pinskia at gcc dot gnu.org
2023-10-24 23:35 ` pinskia at gcc dot gnu.org
2023-10-25 3:43 ` pinskia at gcc dot gnu.org
2023-10-26 18:58 ` cvs-commit at gcc dot gnu.org
2023-10-26 18:58 ` 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).