<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 - zext inhibits shl+and+shr optimization"
href="https://bugs.llvm.org/show_bug.cgi?id=39855">39855</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>zext inhibits shl+and+shr optimization
</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>Common Code Generator Code
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>nikita.ppv@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>For
define i128 @test([4 x i128]* %table, i32 %idx) {
%a = lshr i32 %idx, 4
%b = and i32 %a, 3
%c = zext i32 %b to i64
%d = getelementptr inbounds [4 x i128], [4 x i128]* %table, i64 0, i64 %c
%r = load i128, i128* %d, align 8
ret i128 %r
}
llc generates:
shrl $4, %esi
andl $3, %esi
shlq $4, %rsi
movq (%rdi,%rsi), %rax
movq 8(%rdi,%rsi), %rdx
retq
Doing the same without the zext
define i128 @test([4 x i128]* %table, i64 %idx) {
%a = lshr i64 %idx, 4
%b = and i64 %a, 3
%d = getelementptr inbounds [4 x i128], [4 x i128]* %table, i64 0, i64 %b
%r = load i128, i128* %d, align 8
ret i128 %r
}
results in
andl $48, %esi
movq (%rdi,%rsi), %rax
movq 8(%rdi,%rsi), %rdx
retq
which is the desired output.
This combine is carried out by
<a href="https://github.com/llvm-mirror/llvm/blob/d1c472605b0ff640ff202a7faee1fc3dad0174b6/lib/CodeGen/SelectionDAG/DAGCombiner.cpp#L6177">https://github.com/llvm-mirror/llvm/blob/d1c472605b0ff640ff202a7faee1fc3dad0174b6/lib/CodeGen/SelectionDAG/DAGCombiner.cpp#L6177</a>,
which is able to handle a (shl (and (sra))) chain, but not (shl (zext (and
(sra)))).
Rust bug report: <a href="https://github.com/rust-lang/rust/issues/56057">https://github.com/rust-lang/rust/issues/56057</a></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>