<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 --- - Missed optimization for comparison of uin64_t values on 32-bit platform"
href="https://llvm.org/bugs/show_bug.cgi?id=31924">31924</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Missed optimization for comparison of uin64_t values on 32-bit platform
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</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>LLVM Codegen
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>mizvekov@gmail.com
</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>Consider the following simple example:
bool comp1(__UINT64_TYPE__ a) {
return a >= 0x1234567800000000llu;
}
bool comp2(__UINT64_TYPE__ a) {
__UINT32_TYPE__ b = a >> 32;
return b >= 0x12345678u;
}
When compiled with "-Os -march=i686 -m32 -fomit-frame-pointer" the following
code is generated:
comp1(unsigned long long): # @comp1(unsigned long
long)
mov eax, dword ptr [esp + 8]
shr eax, 3
cmp eax, 38177486
seta al
ret
comp2(unsigned long long): # @comp2(unsigned long
long)
cmp dword ptr [esp + 8], 305419895
seta al
ret
Notice the redundant right shifting of the lhs value in the comp1 version.
For comparison, gcc generates optimal code for both versions:
comp1(unsigned long long):
cmp DWORD PTR [esp+8], 305419895
seta al
ret
comp2(unsigned long long):
cmp DWORD PTR [esp+8], 305419895
seta al
ret
This is the IR emited by clang:
; Function Attrs: norecurse nounwind optsize readnone
define zeroext i1 @_Z5comp1y(i64) local_unnamed_addr #0 {
%2 = icmp ugt i64 %0, 1311768464867721215
ret i1 %2
}
; Function Attrs: norecurse nounwind optsize readnone
define zeroext i1 @_Z5comp2y(i64) local_unnamed_addr #0 {
%2 = lshr i64 %0, 32
%3 = trunc i64 %2 to i32
%4 = icmp ugt i32 %3, 305419895
ret i1 %4
}
So basically the basic structure of the problem is already present when emitted
by the front end, and later optimization passes can't fix it.</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>