<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 - Optimization for min(max) or max(min) pattern in ARM backend generates wrong calculate result"
href="https://bugs.llvm.org/show_bug.cgi?id=48826">48826</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Optimization for min(max) or max(min) pattern in ARM backend generates wrong calculate result
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</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>Backend: ARM
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>yabinc@google.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, smithp352@googlemail.com, Ties.Stuij@arm.com
</td>
</tr></table>
<p>
<div>
<pre>With patch <a href="https://reviews.llvm.org/D87457?id=292224">https://reviews.llvm.org/D87457?id=292224</a>, clang generates wrong
calculation results in some cases:
A case to reproduce the bug is in <a href="https://godbolt.org/z/97W36o">https://godbolt.org/z/97W36o</a>. The operation
list is
like below:
int8 output[];
int16 a = ?;
int16 b = ?;
a += b;
a = min(a, INT8_MAX);
a = max(a, INT8_MIN);
output[i] = a;
It is translated into below assembly:
lsr.w r11, r10, #16
add r0, r11
ssat r0, #8, r0
strb r0, [r6], #1
If a = 145, b = -128, then the correct output[i] should be 17. But here r11 is
using lsr.w to logical shift right,
using zero instead of sign extension to fill the high 16-bit. So it will
overflow and generates a wrong result 127.
In a real example on Android, ldrh.w is used instead of lsr.w, it also uses
zero extension instead of signed extension,
and generates a wrong result.
Before the patch, there is a sxth instruction between the add instruction and
the strb instruction, to make the result
correct. But after the patch, sxth instruction is gone.</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>