public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/113302] New: `x == 1 ? 1 : (x == -1 ? -1 : 0)` should be optimized to `((unsigned)t) + 1 <= 2 ? 0`
@ 2024-01-10 5:59 pinskia at gcc dot gnu.org
2024-01-10 6:02 ` [Bug tree-optimization/113302] " pinskia at gcc dot gnu.org
2024-01-10 6:05 ` pinskia at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-10 5:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113302
Bug ID: 113302
Summary: `x == 1 ? 1 : (x == -1 ? -1 : 0)` should be optimized
to `((unsigned)t) + 1 <= 2 ? 0`
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: enhancement
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
Take:
```
int f(int x)
{
if (x == 1)
return 1;
if (x == -1)
return -1;
if (x == 0)
return 0;
return 0;
}
int g(int x)
{
if (x == 1)
return 1;
if (x == -1)
return -1;
return 0;
}
```
These both should produce:
```
int h(int t)
{
unsigned t1 = t;
t1+=1;
return t1<=2 ? t : 0;
}
```
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug tree-optimization/113302] `x == 1 ? 1 : (x == -1 ? -1 : 0)` should be optimized to `((unsigned)t) + 1 <= 2 ? 0`
2024-01-10 5:59 [Bug tree-optimization/113302] New: `x == 1 ? 1 : (x == -1 ? -1 : 0)` should be optimized to `((unsigned)t) + 1 <= 2 ? 0` pinskia at gcc dot gnu.org
@ 2024-01-10 6:02 ` pinskia at gcc dot gnu.org
2024-01-10 6:05 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-10 6:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113302
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
See Also| |https://github.com/llvm/llv
| |m-project/issues/77558
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I Noticed this while looking into PR 113301 and I also noticed that LLVM could
handle f but not g .
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug tree-optimization/113302] `x == 1 ? 1 : (x == -1 ? -1 : 0)` should be optimized to `((unsigned)t) + 1 <= 2 ? 0`
2024-01-10 5:59 [Bug tree-optimization/113302] New: `x == 1 ? 1 : (x == -1 ? -1 : 0)` should be optimized to `((unsigned)t) + 1 <= 2 ? 0` pinskia at gcc dot gnu.org
2024-01-10 6:02 ` [Bug tree-optimization/113302] " pinskia at gcc dot gnu.org
@ 2024-01-10 6:05 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-10 6:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113302
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This should also optimize to that:
```
int j(int x)
{
int t = x == -1;
int t1 = x == 1;
return t | -t1;
}
```
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-01-10 6:05 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-10 5:59 [Bug tree-optimization/113302] New: `x == 1 ? 1 : (x == -1 ? -1 : 0)` should be optimized to `((unsigned)t) + 1 <= 2 ? 0` pinskia at gcc dot gnu.org
2024-01-10 6:02 ` [Bug tree-optimization/113302] " pinskia at gcc dot gnu.org
2024-01-10 6:05 ` 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).