public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/111763] New: `(a & ~1) | 2` could be done as `(a & ~(1 | 2)) + 2` which allows to use leal
@ 2023-10-10 19:32 pinskia at gcc dot gnu.org
0 siblings, 0 replies; only message in thread
From: pinskia at gcc dot gnu.org @ 2023-10-10 19:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111763
Bug ID: 111763
Summary: `(a & ~1) | 2` could be done as `(a & ~(1 | 2)) + 2`
which allows to use leal
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: enhancement
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
Target: x86_64-linux-gnu
Take:
```
int f1(int in) {
in = (in & ~(unsigned long)1);
in = in | 2;
return in;
}
int f2(int in) {
in = (in & ~(unsigned long)(1|2));
in = in + 2;
return in;
}
```
We currently get:
```
f1:
movl %edi, %eax
andl $-2, %eax
orl $2, %eax
ret
f2:
andl $-4, %edi
leal 2(%rdi), %eax
ret
```
The leal version is better because it saves more move due to leal not being a 2
operand but 3 operand instruction so it could improve register allocation ...
I noticed this whole looking into PR 111762 (and PR 111282) and looking at
clang/LLVM's code generation here .
Also I don't know how often this shows up though.
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-10-10 19:32 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-10 19:32 [Bug target/111763] New: `(a & ~1) | 2` could be done as `(a & ~(1 | 2)) + 2` which allows to use leal 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).