<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 - division 1/a may be optimized better"
href="https://bugs.llvm.org/show_bug.cgi?id=34063">34063</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>division 1/a may be optimized better
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>3.9
</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>Backend: X86
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>konstantin.vladimirov@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Really it is platform-independent optimization bug. Lets look it on x86:
int a = 1;
int
main ()
{
int f = 1 / a;
return (f == 1) ? 0 : 1;
}
compile with:
clang -v
clang version 3.9.0 (tags/RELEASE_390/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
command line:
clang -S -O2 div-bug.c
You shall see:
main: # @main
.cfi_startproc
# BB#0: # %entry
movl a(%rip), %eax
leal 1(%rax), %ecx
cmpl $3, %ecx
sbbb %cl, %cl
cmpl $1, %eax
sete %al
andb %cl, %al
movzbl %al, %eax
xorl $1, %eax
retq
Comparison with 3 in assembler definitely unncessary.
Real problem is in platform independent instruction combiner. It transforms:
%0 = load i32, i32* @a, align 4, !tbaa !1
%div = sdiv i32 1, %0
%cmp = icmp eq i32 %div, 1
to
%0 = load i32, i32* @a, align 4, !tbaa !1
%1 = add i32 %0, 1
%2 = icmp ult i32 %1, 3
%cmp2 = icmp eq i32 %0, 1
%cmp = and i1 %2, %cmp2
Of course check if %1 less then 3 is excessive for this case.</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>