public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/112403] New: `s+ (a?-1:1)` and `a?s-1:s+1` produce two different code generation
@ 2023-11-06 7:03 pinskia at gcc dot gnu.org
2023-11-12 21:17 ` [Bug middle-end/112403] " pinskia at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-06 7:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112403
Bug ID: 112403
Summary: `s+ (a?-1:1)` and `a?s-1:s+1` produce two different
code generation
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Blocks: 94274
Target Milestone: ---
Target: aarch64
Take:
```
int
foo(int t1, int s)
{
int t;
if (t1 >= 0)
t=1;
else
t=-1;
s+=t;
return s;
}
int
foo1(int t1, int s)
{
if (t1 >= 0)
s++;
else
s--;
return s;
}
```
This current produces:
```
foo:
cmp w0, 0
mov w2, 1
csneg w2, w2, w2, ge
add w0, w2, w1
ret
foo1:
cmp w0, 0
sub w0, w1, #1
csinc w0, w0, w1, lt
ret
```
But we should be able to even just produce:
```
asr w8, w0, #31 // a >= 0 ? -1 : 0
orr w8, w8, #0x1 // |1 (or a >= ? -1 : 1)
add w0, w8, w1 // s+=that
```
Note on x86, the foo is optimal even:
```
sarl $31, %edi
orl $1, %edi
leal (%rdi,%rsi), %eax
```
I should note this blocks PR 94274 work.
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94274
[Bug 94274] fold phi whose incoming args are defined from binary operations
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug middle-end/112403] `s+ (a?-1:1)` and `a?s-1:s+1` produce two different code generation
2023-11-06 7:03 [Bug middle-end/112403] New: `s+ (a?-1:1)` and `a?s-1:s+1` produce two different code generation pinskia at gcc dot gnu.org
@ 2023-11-12 21:17 ` pinskia at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-12 21:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112403
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-11-12 21:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-06 7:03 [Bug middle-end/112403] New: `s+ (a?-1:1)` and `a?s-1:s+1` produce two different code generation pinskia at gcc dot gnu.org
2023-11-12 21:17 ` [Bug middle-end/112403] " 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).