<html>
<head>
<base href="https://llvm.org/bugs/" />
</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 --- - replacing variable by a constant breaks subtract-with-borrow (sbb) optimization"
href="https://llvm.org/bugs/show_bug.cgi?id=31754">31754</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>replacing variable by a constant breaks subtract-with-borrow (sbb) optimization
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</td>
</tr>
<tr>
<th>Version</th>
<td>3.9
</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>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>vincent-llvm@vinc17.net
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>In some C code, the generated x86_64 code gets worse when I replace a variable
by a constant. Example:
typedef unsigned long T;
void sub (T *p, T u, T v, T w)
{
p[0] = w - v;
p[1] = u - (w < v);
}
void sub0 (T *p, T u, T v)
{
T w = 0;
p[0] = w - v;
p[1] = u - (w < v);
}
void sub1 (T *p, T u, T v)
{
T w = 1;
p[0] = w - v;
p[1] = u - (w < v);
}
sub0 and sub1 are like sub, except that w is 0 and 1 respectively.
With Clang 3.9.1 under Debian/unstable, I get from "clang-3.9 -O3 -S":
sub: # @sub
.cfi_startproc
# BB#0:
subq %rdx, %rcx
movq %rcx, (%rdi)
sbbq $0, %rsi
movq %rsi, 8(%rdi)
retq
sub0: # @sub0
.cfi_startproc
# BB#0:
movq %rdx, %rax
negq %rax
movq %rax, (%rdi)
cmpq $1, %rdx
adcq $-1, %rsi
movq %rsi, 8(%rdi)
retq
sub1: # @sub1
.cfi_startproc
# BB#0:
movl $1, %eax
subq %rdx, %rax
movq %rax, (%rdi)
xorl %eax, %eax
cmpq $1, %rdx
seta %al
subq %rax, %rsi
movq %rsi, 8(%rdi)
retq
For sub0 and sub1, I would expect
sbbq $0, %rsi
like for sub.</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>