<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 - [SimplifyCFG] Failure to use select min/max for the saturated operations instead of phi"
href="https://bugs.llvm.org/show_bug.cgi?id=48641">48641</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[SimplifyCFG] Failure to use select min/max for the saturated operations instead of phi
</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>Scalar Optimizations
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>david.bolvansky@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>#define OP +
int foo_add_ok (const unsigned char *tmp, int i, int val)
{
int R = (tmp[i] OP val);
return ((R>0xFF)?0xFF:(((R)<0)?0:(R)));
}
int foo_add2_bad(const unsigned char *tmp, int i, int val)
{
return (((tmp[i] OP val)>0xFF)?0xFF:(((tmp[i] OP val)<0)?0:(tmp[i] OP val)));
}
Clang:
foo_add_ok(unsigned char const*, int, int): # @foo_add_ok(unsigned char const*,
int, int)
movsxd rax, esi
movzx ecx, byte ptr [rdi + rax]
xor eax, eax
add ecx, edx
cmovs ecx, eax
cmp ecx, 255
mov eax, 255
cmovl eax, ecx
ret
foo_add2_bad(unsigned char const*, int, int): # @foo_add2_bad(unsigned char
const*, int, int)
movsxd rax, esi
movzx ecx, byte ptr [rdi + rax]
add ecx, edx
cmp ecx, 255
jle .LBB1_1
mov eax, 255
ret
.LBB1_1:
xor eax, eax
test ecx, ecx
cmovns eax, ecx
ret
GCC:
foo_add_ok(unsigned char const*, int, int):
movsx rsi, esi
movzx eax, BYTE PTR [rdi+rsi]
add eax, edx
mov edx, 0
cmovs eax, edx
mov edx, 255
cmp eax, 255
cmovg eax, edx
ret
foo_add2_bad(unsigned char const*, int, int):
movsx rsi, esi
movzx eax, BYTE PTR [rdi+rsi]
add eax, edx
mov edx, 0
cmovs eax, edx
mov edx, 255
cmp eax, 255
cmovg eax, edx
ret
<a href="https://godbolt.org/z/zdoo8f">https://godbolt.org/z/zdoo8f</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>