<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 --- - extra zeroing move operation executed"
href="http://llvm.org/bugs/show_bug.cgi?id=17113">17113</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>extra zeroing move operation executed
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</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>Backend: X86
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>kkhoo@perfwizard.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>$ ./clang -v
clang version 3.4 (trunk 189776)
Target: x86_64-apple-darwin11.4.2
Thread model: posix
$ cat power_of_2.c
unsigned int power_of_two(unsigned int x) {
return x && !(x & (x - 1));
}
$ ./clang -S -O3 -fomit-frame-pointer power_of_2.c -o /dev/stdout
.section __TEXT,__text,regular,pure_instructions
.globl _power_of_two
.align 4, 0x90
_power_of_two: ## @power_of_two
.cfi_startproc
## BB#0: ## %entry
## kill: EDI<def> EDI<kill> RDI<def>
xorl %eax, %eax
testl %edi, %edi
je LBB0_2
## BB#1: ## %land.rhs
leal -1(%rdi), %eax
testl %edi, %eax
sete %al
LBB0_2: ## %land.end
movzbl %al, %eax
ret
...
I hope I'm not missing something in reading this asm...
In the case where x==0, we execute the 'test' to see if x==0 and then 'je'
(jump if equal to 0) to the 'movzb' instruction. However, we've already ensured
that %eax is zeroed out at this point via the 'xor'. Couldn't we have jumped
straight to the 'ret'?</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>