[prev in list] [next in list] [prev in thread] [next in thread]
List: llvm-bugs
Subject: [LLVMbugs] [Bug 19903] New: Missed strlen==0 optimization
From: bugzilla-daemon () llvm ! org
Date: 2014-05-30 22:04:25
Message-ID: bug-19903-206 () http ! llvm ! org/bugs/
[Download RAW message or body]
--1401487466.d2c8e35a1.31056
Date: Fri, 30 May 2014 17:04:26 -0500
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
http://llvm.org/bugs/show_bug.cgi?id=19903
Bug ID: 19903
Summary: Missed strlen==0 optimization
Product: new-bugs
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: new bugs
Assignee: unassignedbugs@nondot.org
Reporter: dnovillo@google.com
CC: dblaikie@gmail.com, llvmbugs@cs.uiuc.edu
Classification: Unclassified
The optimizer will generally optimize a strlen==0 comparison, but under certain
circumstances, it will miss the opportunity:
int foo(const char *s) {
if (strlen(s) == 0) {
return 42;
}
return strlen(s);
}
Instead of calling strlen on the else branch, LLVM will float the call to
strlen at the top:
.Ltmp0:
.cfi_def_cfa_offset 16
callq strlen
testq %rax, %rax
movl $42, %ecx
cmovnel %eax, %ecx
movl %ecx, %eax
popq %rdx
retq
Whereas GCC 4.6 will first avoid calling strlen until it really needs to:
.cfi_def_cfa_offset 16
cmpb $0, (%rdi)
movl $42, %eax
jne .L5
addq $8, %rsp
.cfi_remember_state
.cfi_def_cfa_offset 8
ret
.p2align 4,,10
.p2align 3
.L5:
.cfi_restore_state
call strlen
addq $8, %rsp
.cfi_def_cfa_offset 8
.p2align 4,,1
ret
I'm not sure how important this is. I only caught it trying to test something
else.
--
You are receiving this mail because:
You are on the CC list for the bug.
--1401487466.d2c8e35a1.31056
Date: Fri, 30 May 2014 17:04:26 -0500
MIME-Version: 1.0
Content-Type: text/html; charset="UTF-8"
<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - Missed strlen==0 optimization"
href="http://llvm.org/bugs/show_bug.cgi?id=19903">19903</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Missed strlen==0 optimization
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>dnovillo@google.com
</td>
</tr>
<tr>
<th>CC</th>
<td>dblaikie@gmail.com, llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>The optimizer will generally optimize a strlen==0 comparison, but under certain
circumstances, it will miss the opportunity:
int foo(const char *s) {
if (strlen(s) == 0) {
return 42;
}
return strlen(s);
}
Instead of calling strlen on the else branch, LLVM will float the call to
strlen at the top:
.Ltmp0:
.cfi_def_cfa_offset 16
callq strlen
testq %rax, %rax
movl $42, %ecx
cmovnel %eax, %ecx
movl %ecx, %eax
popq %rdx
retq
Whereas GCC 4.6 will first avoid calling strlen until it really needs to:
.cfi_def_cfa_offset 16
cmpb $0, (%rdi)
movl $42, %eax
jne .L5
addq $8, %rsp
.cfi_remember_state
.cfi_def_cfa_offset 8
ret
.p2align 4,,10
.p2align 3
.L5:
.cfi_restore_state
call strlen
addq $8, %rsp
.cfi_def_cfa_offset 8
.p2align 4,,1
ret
I'm not sure how important this is. I only caught it trying to test something
else.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>
--1401487466.d2c8e35a1.31056--
_______________________________________________
LLVMbugs mailing list
LLVMbugs@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic