public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/64753] New: Redundant cmp instruction on x86_64
@ 2015-01-23 15:06 rv at rasmusvillemoes dot dk
2015-01-28 12:58 ` [Bug target/64753] " rv at rasmusvillemoes dot dk
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: rv at rasmusvillemoes dot dk @ 2015-01-23 15:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64753
Bug ID: 64753
Summary: Redundant cmp instruction on x86_64
Product: gcc
Version: 5.0
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: rv at rasmusvillemoes dot dk
Host: x86_64
Target: x86_64
The linux kernel's library strncmp is this:
int strncmp(const char *cs, const char *ct, size_t count)
{
unsigned char c1, c2;
while (count) {
c1 = *cs++;
c2 = *ct++;
if (c1 != c2)
return c1 < c2 ? -1 : 1;
if (!c1)
break;
count--;
}
return 0;
}
Compiling with gcc -O2 -S I get this:
strncmp:
.LFB0:
.cfi_startproc
testq %rdx, %rdx
je .L10
movzbl (%rdi), %ecx
movzbl (%rsi), %r8d
# cmpb %r8b, %cl
# jne .L3
testb %cl, %cl
je .L10
subq $1, %rdx
xorl %eax, %eax
jmp .L4
.p2align 4,,10
.p2align 3
.L6:
movzbl 1(%rdi,%rax), %ecx
movzbl 1(%rsi,%rax), %r8d
# cmpb %r8b, %cl
# jne .L3
addq $1, %rax
testb %cl, %cl
je .L10
.L4:
cmpq %rdx, %rax
jne .L6
.L10:
xorl %eax, %eax
ret
.p2align 4,,10
.p2align 3
.L3:
cmpb %r8b, %cl
sbbl %eax, %eax
orl $1, %eax
ret
.cfi_endproc
At the two places marked # we do a cmp and a conditional jump to .L3, where for
good measure the same cmp is done again... there's no other path to .L3, so it
would seem that simply omitting that extra cmp should be ok.
This is with gcc-5.0 (GCC) 5.0.0 20150112 (experimental), but I see the same
with gcc (Debian 4.7.2-5) 4.7.2.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug target/64753] Redundant cmp instruction on x86_64
2015-01-23 15:06 [Bug target/64753] New: Redundant cmp instruction on x86_64 rv at rasmusvillemoes dot dk
@ 2015-01-28 12:58 ` rv at rasmusvillemoes dot dk
2015-01-28 13:31 ` ubizjak at gmail dot com
2024-03-17 7:39 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: rv at rasmusvillemoes dot dk @ 2015-01-28 12:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64753
--- Comment #1 from Rasmus Villemoes <rv at rasmusvillemoes dot dk> ---
FWIW, I wrote a stupid script looking for the pattern
<test/cmp instruction>
<(conditional) jump to abcd>
...
abcd: <same test/cmp instruction>
Compiling a defconfig linux kernel with gcc 4.7 gives 201 instances, 5.0 gives
252. The second test/cmp may not be redundant in all cases, but at least the
jump target could be adjusted to the instruction following abcd. I filtered out
cases where the jump itself was a jump target (so the only path to it is
through the preceding test/cmp), though that didn't actually remove anything.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug target/64753] Redundant cmp instruction on x86_64
2015-01-23 15:06 [Bug target/64753] New: Redundant cmp instruction on x86_64 rv at rasmusvillemoes dot dk
2015-01-28 12:58 ` [Bug target/64753] " rv at rasmusvillemoes dot dk
@ 2015-01-28 13:31 ` ubizjak at gmail dot com
2024-03-17 7:39 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: ubizjak at gmail dot com @ 2015-01-28 13:31 UTC (permalink / raw)
To: gcc-bugs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="UTF-8", Size: 3061 bytes --]
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64753
--- Comment #2 from Uroš Bizjak <ubizjak at gmail dot com> ---
(In reply to Rasmus Villemoes from comment #0)
> At the two places marked # we do a cmp and a conditional jump to .L3, where
> for good measure the same cmp is done again... there's no other path to .L3,
> so it would seem that simply omitting that extra cmp should be ok.
IIRC postreload redundant compare elimination pass removes these redundant
compares. Unfortunately, the pass is not yet enabled for x86 targets.
>From gcc-bugs-return-475242-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Wed Jan 28 13:31:04 2015
Return-Path: <gcc-bugs-return-475242-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 17995 invoked by alias); 28 Jan 2015 13:31:04 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 17468 invoked by uid 48); 28 Jan 2015 13:30:59 -0000
From: "pault at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/64757] [5 Regression] ICE in fold_convert_loc, at fold-const.c:2353
Date: Wed, 28 Jan 2015 13:31:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: fortran
X-Bugzilla-Version: 5.0
X-Bugzilla-Keywords: ice-on-valid-code
X-Bugzilla-Severity: normal
X-Bugzilla-Who: pault at gcc dot gnu.org
X-Bugzilla-Status: NEW
X-Bugzilla-Priority: P4
X-Bugzilla-Assigned-To: pault at gcc dot gnu.org
X-Bugzilla-Target-Milestone: 5.0
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: cc assigned_to attachments.created
Message-ID: <bug-64757-4-ELTYTvJFpC@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-64757-4@http.gcc.gnu.org/bugzilla/>
References: <bug-64757-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-01/txt/msg03236.txt.bz2
Content-length: 681
https://gcc.gnu.org/bugzilla/show_bug.cgi?idd757
Paul Thomas <pault at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |pault at gcc dot gnu.org
Assignee|unassigned at gcc dot gnu.org |pault at gcc dot gnu.org
--- Comment #7 from Paul Thomas <pault at gcc dot gnu.org> ---
Created attachment 34607
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id4607&actioníit
Draft patch for the PR
I believe that this regression was caused by the fix for pr60357.
The patch is regtesting right now.
Paul
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug target/64753] Redundant cmp instruction on x86_64
2015-01-23 15:06 [Bug target/64753] New: Redundant cmp instruction on x86_64 rv at rasmusvillemoes dot dk
2015-01-28 12:58 ` [Bug target/64753] " rv at rasmusvillemoes dot dk
2015-01-28 13:31 ` ubizjak at gmail dot com
@ 2024-03-17 7:39 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-17 7:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64753
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Target Milestone|--- |9.0
Resolution|--- |FIXED
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
r8-647-g4f0473fe89e68b
and some more improvement that was done in GCC 9.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-03-17 7:39 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-23 15:06 [Bug target/64753] New: Redundant cmp instruction on x86_64 rv at rasmusvillemoes dot dk
2015-01-28 12:58 ` [Bug target/64753] " rv at rasmusvillemoes dot dk
2015-01-28 13:31 ` ubizjak at gmail dot com
2024-03-17 7:39 ` 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).