public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/50131] New: Optimize x = -1 with "or" for -O
@ 2011-08-19 20:58 hjl.tools at gmail dot com
2011-08-19 21:19 ` [Bug target/50131] " hjl.tools at gmail dot com
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: hjl.tools at gmail dot com @ 2011-08-19 20:58 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50131
Bug #: 50131
Summary: Optimize x = -1 with "or" for -O
Classification: Unclassified
Product: gcc
Version: 4.7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: hjl.tools@gmail.com
CC: ubizjak@gmail.com
[hjl@gnu-6 rtm-1]$ cat x.c
int
foo1 ()
{
return -1;
}
short
foo2 ()
{
return -1;
}
long long
foo3 ()
{
return -1;
}
[hjl@gnu-6 rtm-1]$ gcc -S -Os x.c
[hjl@gnu-6 rtm-1]$ cat x.s
.file "x.c"
.text
.globl foo1
.type foo1, @function
foo1:
.LFB0:
.cfi_startproc
orl $-1, %eax
ret
.cfi_endproc
.LFE0:
.size foo1, .-foo1
.globl foo2
.type foo2, @function
foo2:
.LFB1:
.cfi_startproc
orl $-1, %eax
ret
.cfi_endproc
.LFE1:
.size foo2, .-foo2
.globl foo3
.type foo3, @function
foo3:
.LFB2:
.cfi_startproc
orq $-1, %rax
ret
.cfi_endproc
.LFE2:
.size foo3, .-foo3
.ident "GCC: (GNU) 4.6.0 20110603 (Red Hat 4.6.0-10)"
.section .note.GNU-stack,"",@progbits
[hjl@gnu-6 rtm-1]$ gcc -S -O2 x.c
[hjl@gnu-6 rtm-1]$ cat x.s
.file "x.c"
.text
.p2align 4,,15
.globl foo1
.type foo1, @function
foo1:
.LFB0:
.cfi_startproc
movl $-1, %eax
ret
.cfi_endproc
.LFE0:
.size foo1, .-foo1
.p2align 4,,15
.globl foo2
.type foo2, @function
foo2:
.LFB1:
.cfi_startproc
movl $-1, %eax
ret
.cfi_endproc
.LFE1:
.size foo2, .-foo2
.p2align 4,,15
.globl foo3
.type foo3, @function
foo3:
.LFB2:
.cfi_startproc
movq $-1, %rax
ret
.cfi_endproc
.LFE2:
.size foo3, .-foo3
.ident "GCC: (GNU) 4.6.0 20110603 (Red Hat 4.6.0-10)"
.section .note.GNU-stack,"",@progbits
[hjl@gnu-6 rtm-1]$
I was expecting "or" for -O.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug target/50131] Optimize x = -1 with "or" for -O
2011-08-19 20:58 [Bug target/50131] New: Optimize x = -1 with "or" for -O hjl.tools at gmail dot com
@ 2011-08-19 21:19 ` hjl.tools at gmail dot com
2011-08-20 8:37 ` jakub at gcc dot gnu.org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: hjl.tools at gmail dot com @ 2011-08-19 21:19 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50131
--- Comment #1 from H.J. Lu <hjl.tools at gmail dot com> 2011-08-19 20:58:00 UTC ---
There are 1273 "movl $0xffffffff," and 924 "movq 0xffffffffffffffff,"
in cc1plus. This change can reduce cc1plus size by 6242 bytes.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug target/50131] Optimize x = -1 with "or" for -O
2011-08-19 20:58 [Bug target/50131] New: Optimize x = -1 with "or" for -O hjl.tools at gmail dot com
2011-08-19 21:19 ` [Bug target/50131] " hjl.tools at gmail dot com
@ 2011-08-20 8:37 ` jakub at gcc dot gnu.org
2011-08-20 20:04 ` hjl.tools at gmail dot com
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2011-08-20 8:37 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50131
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-08-20 08:32:12 UTC ---
Is or $-1, reg on all CPUs equally expensive to mov $-1, reg though (as or
generally needs the previous reg content while mov does not; I know some CPUs
special case xor reg, reg, but I doubt or $-1, reg is special cased)?
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug target/50131] Optimize x = -1 with "or" for -O
2011-08-19 20:58 [Bug target/50131] New: Optimize x = -1 with "or" for -O hjl.tools at gmail dot com
2011-08-19 21:19 ` [Bug target/50131] " hjl.tools at gmail dot com
2011-08-20 8:37 ` jakub at gcc dot gnu.org
@ 2011-08-20 20:04 ` hjl.tools at gmail dot com
2011-08-21 9:20 ` rguenth at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: hjl.tools at gmail dot com @ 2011-08-20 20:04 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50131
--- Comment #3 from H.J. Lu <hjl.tools at gmail dot com> 2011-08-20 19:44:49 UTC ---
(In reply to comment #2)
> Is or $-1, reg on all CPUs equally expensive to mov $-1, reg though (as or
> generally needs the previous reg content while mov does not; I know some CPUs
> special case xor reg, reg, but I doubt or $-1, reg is special cased)?
We should add a new x86 optimization flag and turn it on
only if it helps for the processor to be optimized.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug target/50131] Optimize x = -1 with "or" for -O
2011-08-19 20:58 [Bug target/50131] New: Optimize x = -1 with "or" for -O hjl.tools at gmail dot com
` (2 preceding siblings ...)
2011-08-20 20:04 ` hjl.tools at gmail dot com
@ 2011-08-21 9:20 ` rguenth at gcc dot gnu.org
2011-08-23 14:57 ` hjl.tools at gmail dot com
2021-12-15 1:34 ` pinskia at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-08-21 9:20 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50131
--- Comment #4 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-08-21 09:19:28 UTC ---
I'm sure or $-1,reg doesn't avoid the data dependence on reg and may even
result in hitting partial reg stall issues. Surely xor reg,reg; not reg
might be another alternative?
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug target/50131] Optimize x = -1 with "or" for -O
2011-08-19 20:58 [Bug target/50131] New: Optimize x = -1 with "or" for -O hjl.tools at gmail dot com
` (3 preceding siblings ...)
2011-08-21 9:20 ` rguenth at gcc dot gnu.org
@ 2011-08-23 14:57 ` hjl.tools at gmail dot com
2021-12-15 1:34 ` pinskia at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: hjl.tools at gmail dot com @ 2011-08-23 14:57 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50131
H.J. Lu <hjl.tools at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |sergos.gnu at gmail dot com
--- Comment #5 from H.J. Lu <hjl.tools at gmail dot com> 2011-08-23 14:38:58 UTC ---
We do have
/* X86_TUNE_MOVE_M1_VIA_OR: On pentiums, it is faster to load -1 via OR
than a MOV. */
m_PENT,
We should check how it performs on the current processors.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug target/50131] Optimize x = -1 with "or" for -O
2011-08-19 20:58 [Bug target/50131] New: Optimize x = -1 with "or" for -O hjl.tools at gmail dot com
` (4 preceding siblings ...)
2011-08-23 14:57 ` hjl.tools at gmail dot com
@ 2021-12-15 1:34 ` pinskia at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-15 1:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50131
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2021-12-15
Keywords| |missed-optimization
Ever confirmed|0 |1
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-12-15 1:34 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-19 20:58 [Bug target/50131] New: Optimize x = -1 with "or" for -O hjl.tools at gmail dot com
2011-08-19 21:19 ` [Bug target/50131] " hjl.tools at gmail dot com
2011-08-20 8:37 ` jakub at gcc dot gnu.org
2011-08-20 20:04 ` hjl.tools at gmail dot com
2011-08-21 9:20 ` rguenth at gcc dot gnu.org
2011-08-23 14:57 ` hjl.tools at gmail dot com
2021-12-15 1: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).