<html>
<head>
<base href="https://bugs.llvm.org/">
</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 - Redundant branches with ctlz and cttz"
href="https://bugs.llvm.org/show_bug.cgi?id=48123">48123</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Redundant branches with ctlz and cttz
</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>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</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>diggsey@googlemail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>craig.topper@gmail.com, llvm-bugs@lists.llvm.org, llvm-dev@redking.me.uk, pengfei.wang@intel.com, spatel+llvm@rotateright.com
</td>
</tr></table>
<p>
<div>
<pre>Rust code:
```rust
pub fn can_represent_as_f64(x: u64) -> bool {
x.leading_zeros() + x.trailing_zeros() >= 11
}
```
LLVM IR:
```llvm
define zeroext i1
@_ZN10playground20can_represent_as_f6417h8c9d47bab619cb5fE(i64 %x) unnamed_addr
#0 {
start:
%0 = tail call i64 @llvm.ctlz.i64(i64 %x, i1 false) #2, !range !2
%1 = trunc i64 %0 to i32
%2 = tail call i64 @llvm.cttz.i64(i64 %x, i1 false) #2, !range !2
%3 = trunc i64 %2 to i32
%_2 = add nuw nsw i32 %1, %3
%4 = icmp ugt i32 %_2, 10
ret i1 %4
}
```
Assembly:
```asm
playground::can_represent_as_f64:
mov eax, 64
mov ecx, 64
test rdi, rdi ; Initial test for zero and branch
je .LBB0_2
bsr rcx, rdi
xor rcx, 63
.LBB0_2:
test rdi, rdi ; Second test for zero and branch
je .LBB0_4
bsf rax, rdi
.LBB0_4:
add ecx, eax
cmp ecx, 10
seta al
ret
```
Instead of performing the comparison twice, the code should immediately branch
to LBB0_4.</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>