public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/112385] New: `(2 >> a) ^ (5 >> a)` is not optimized to `7 >> a` is 2 and 5 differ in signedness
@ 2023-11-05 0:00 pinskia at gcc dot gnu.org
2023-11-05 0:03 ` [Bug tree-optimization/112385] " pinskia at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-05 0:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112385
Bug ID: 112385
Summary: `(2 >> a) ^ (5 >> a)` is not optimized to `7 >> a` is
2 and 5 differ in signedness
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 a)
{
return (2 >> a) ^ (5u >> a);
}
```
This should be optimized to:
```
return (7 >> a);
```
But currently does not.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/112385] `(2 >> a) ^ (5 >> a)` is not optimized to `7 >> a` is 2 and 5 differ in signedness
2023-11-05 0:00 [Bug tree-optimization/112385] New: `(2 >> a) ^ (5 >> a)` is not optimized to `7 >> a` is 2 and 5 differ in signedness pinskia at gcc dot gnu.org
@ 2023-11-05 0:03 ` pinskia at gcc dot gnu.org
2023-11-05 0:08 ` pinskia at gcc dot gnu.org
2023-11-12 22:38 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-05 0:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112385
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note a more complex case like:
```
int f(int a, unsigned b, int c)
{
c &= 0xffff;
return (c >> a) ^ (b >> a);
}
```
Should also be optimized to:
```
int f(int a, unsigned b, int c)
{
c &= 0xffff;
return (c^b) >> a;
}
```
That is if both are known to be non-negative we can do the combining.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/112385] `(2 >> a) ^ (5 >> a)` is not optimized to `7 >> a` is 2 and 5 differ in signedness
2023-11-05 0:00 [Bug tree-optimization/112385] New: `(2 >> a) ^ (5 >> a)` is not optimized to `7 >> a` is 2 and 5 differ in signedness pinskia at gcc dot gnu.org
2023-11-05 0:03 ` [Bug tree-optimization/112385] " pinskia at gcc dot gnu.org
@ 2023-11-05 0:08 ` pinskia at gcc dot gnu.org
2023-11-12 22:38 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-05 0:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112385
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
We can even do it if we know the unsigned value does not have the last bit set.
That is:
```
int f(int a, unsigned b, int c)
{
b &= 0xffff;
return (c >> a) ^ (b >> a);
}
```
Note clang(LLVM) does not handle the above.
The way LLVM handles the others is it changes ashift to lshift if the value is
known to be non-negative. But since in the gimple level we are dealing with
types we can't do that in a nice way; RTL level on the other hand yes that can
be done (though nonzero bits is limited there).
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/112385] `(2 >> a) ^ (5 >> a)` is not optimized to `7 >> a` is 2 and 5 differ in signedness
2023-11-05 0:00 [Bug tree-optimization/112385] New: `(2 >> a) ^ (5 >> a)` is not optimized to `7 >> a` is 2 and 5 differ in signedness pinskia at gcc dot gnu.org
2023-11-05 0:03 ` [Bug tree-optimization/112385] " pinskia at gcc dot gnu.org
2023-11-05 0:08 ` pinskia at gcc dot gnu.org
@ 2023-11-12 22:38 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-12 22:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112385
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Last reconfirmed| |2023-11-12
Status|UNCONFIRMED |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |pinskia at gcc dot gnu.org
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Mine, I will handle this.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-11-12 22:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-05 0:00 [Bug tree-optimization/112385] New: `(2 >> a) ^ (5 >> a)` is not optimized to `7 >> a` is 2 and 5 differ in signedness pinskia at gcc dot gnu.org
2023-11-05 0:03 ` [Bug tree-optimization/112385] " pinskia at gcc dot gnu.org
2023-11-05 0:08 ` pinskia at gcc dot gnu.org
2023-11-12 22:38 ` 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).