public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/112382] New: `(a&b) != a` where a is known to have one known bit set is not optimized to ((~b&a)>>shift) & 1
@ 2023-11-04 21:09 pinskia at gcc dot gnu.org
2023-11-06 8:11 ` [Bug middle-end/112382] " rguenth at gcc dot gnu.org
2023-11-07 3:34 ` pinskia at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-04 21:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112382
Bug ID: 112382
Summary: `(a&b) != a` where a is known to have one known bit
set is not optimized to ((~b&a)>>shift) & 1
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: enhancement
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
Take:
```
int f(int a, int b)
{
a &= 0x10;
return (a&b) < a;
}
int f1(unsigned a, unsigned b)
{
a &= 0x10;
return (a&b) != a;
}
int f2(unsigned a, unsigned b)
{
a &= 0x10;
unsigned c = (a&b) ^ a;
return c>>4;
}
int f3(unsigned a, unsigned b)
{
unsigned c = (~b)&a;
return (c>>4) & 1;
}
```
These all should produce the same code. Right now f2 and f3 produce the best
code on x86 (especially with BMI enabled) and aarch64
note f to f1 is really PR 112093 .
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug middle-end/112382] `(a&b) != a` where a is known to have one known bit set is not optimized to ((~b&a)>>shift) & 1
2023-11-04 21:09 [Bug middle-end/112382] New: `(a&b) != a` where a is known to have one known bit set is not optimized to ((~b&a)>>shift) & 1 pinskia at gcc dot gnu.org
@ 2023-11-06 8:11 ` rguenth at gcc dot gnu.org
2023-11-07 3:34 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-11-06 8:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112382
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target| |x86_64-*-*
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Note ((~b&a)>>shift) & 1 is two more GIMPLE ops than (a&b) != a so I'd
expect the reverse transform on GIMPLE and maybe target specific expansion
tweaks (or combine at work).
Mangling the testcases to expect CSE with the (a&b) != a would be the thing
to test on GIMPLE (maybe simply expect ICF to happen?!)
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug middle-end/112382] `(a&b) != a` where a is known to have one known bit set is not optimized to ((~b&a)>>shift) & 1
2023-11-04 21:09 [Bug middle-end/112382] New: `(a&b) != a` where a is known to have one known bit set is not optimized to ((~b&a)>>shift) & 1 pinskia at gcc dot gnu.org
2023-11-06 8:11 ` [Bug middle-end/112382] " rguenth at gcc dot gnu.org
@ 2023-11-07 3:34 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-07 3:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112382
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #1)
> Note ((~b&a)>>shift) & 1 is two more GIMPLE ops than (a&b) != a so I'd
> expect the reverse transform on GIMPLE and maybe target specific expansion
> tweaks (or combine at work).
Right, that is why I put the component as middle-end. Specifically because I
think `(a&b) != a` should be the Canonical form and only expanded either in
isel or expand .
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-11-07 3:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-04 21:09 [Bug middle-end/112382] New: `(a&b) != a` where a is known to have one known bit set is not optimized to ((~b&a)>>shift) & 1 pinskia at gcc dot gnu.org
2023-11-06 8:11 ` [Bug middle-end/112382] " rguenth at gcc dot gnu.org
2023-11-07 3:34 ` 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).