<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 - [AArch64] Peephole pass incorrectly removes comparison"
href="https://bugs.llvm.org/show_bug.cgi?id=51476">51476</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[AArch64] Peephole pass incorrectly removes comparison
</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>Linux
</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: AArch64
</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>arnaud.degrandmaison@arm.com, llvm-bugs@lists.llvm.org, smithp352@googlemail.com, Ties.Stuij@arm.com
</td>
</tr>
<tr>
<th>Blocks</th>
<td>51236
</td>
</tr></table>
<p>
<div>
<pre>target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
target triple = "aarch64-unknown-linux-gnu"
define void @test(i8 %arg) {
%tmp = alloca i8
%cmp1 = icmp ne i8 %arg, 1
%zext = zext i1 %cmp1 to i8
store i8 %zext, i8* %tmp
%zext2 = load i8, i8* %tmp
%cmp2 = icmp eq i8 %zext2, 3
br i1 %cmp2, label %exit, label %do_call
do_call:
call void @unknown(i8 %zext2)
ret void
exit:
ret void
}
declare void @unknown(i8)
Running through llc produces:
// %bb.0:
str x30, [sp, #-16]! // 8-byte Folded Spill
.cfi_def_cfa_offset 16
.cfi_offset w30, -16
and w8, w0, #0xff
cmp w8, #1
cset w0, ne
strb w0, [sp, #12]
b.ne .LBB0_2
// %bb.1: // %do_call
bl unknown
.LBB0_2: // %common.ret
ldr x30, [sp], #16 // 8-byte Folded Reload
ret
Note how the final comparison to #3 has now reuses the result of the comparison
to #1.
This is caused by the new optimization introduced in
<a href="https://reviews.llvm.org/D98564">https://reviews.llvm.org/D98564</a>. From a cursory reading, this optimization was
written under the assumption that CmpValue==1 means that the comparison is
against #1, while analyzeCompare() canonicalizes the comparison such that
CmpValue==1 indicates a comparison against any non-zero value.</pre>
</div>
</p>
<div id="referenced">
<hr style="border: 1px dashed #969696">
<b>Referenced Bugs:</b>
<ul>
<li>
[<a class="bz_bug_link
bz_status_NEW "
title="NEW - [meta] 13.0.0 Release Blockers"
href="https://bugs.llvm.org/show_bug.cgi?id=51236">Bug 51236</a>] [meta] 13.0.0 Release Blockers
</li>
</ul>
</div>
<br>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>