<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 - Missed optimizations due to incomplete range analysis"
href="https://bugs.llvm.org/show_bug.cgi?id=34517">34517</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Missed optimizations due to incomplete range analysis
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</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>-New Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>gonzalobg88@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Given this:
short fn1(short p) {
short c = p / 32769;
return c;
}
int fn2(signed char p) {
int c = p / 129;
return c;
}
int fn3(short p4, int p5) {
int v = 0;
if ((p4 - 32779) - !p5)
v = 7;
return v;
}
int fn4(int p, int q) {
int a = q + (p % 6) / 9;
return a;
}
int fn5(int p) {
return (1 / p) / 100;
}
int fn6(int p5, int p6) {
int a, c, v;
v = -!p5;
a = v + 7;
c = (4 % a);
return c;
}
int fn7(int p4, int p5) {
int a = 5;
if ((5 % p5) / 9)
a = p4;
return a;
}
GCC -O3 produces this output:
fn1(short):
xor eax, eax
ret
fn2(signed char):
xor eax, eax
ret
fn3(short, int):
mov eax, 7
ret
fn4(int, int):
mov eax, esi
ret
fn5(int):
xor eax, eax
ret
fn6(int, int):
mov eax, 4
ret
fn7(int, int):
mov eax, 5
ret
but clang -O3 produces this output:
fn1(short): # @fn1(short)
movsxd rax, edi
imul rax, rax, 1073709057
mov rcx, rax
shr rcx, 63
shr rax, 45
add eax, ecx
ret
fn2(signed char): # @fn2(signed char)
movsxd rax, edi
imul rax, rax, 266354561
mov rcx, rax
shr rcx, 63
sar rax, 35
add eax, ecx
ret
fn3(short, int): # @fn3(short, int)
add edi, -32779
xor eax, eax
test esi, esi
sete al
xor ecx, ecx
cmp edi, eax
mov eax, 7
cmove eax, ecx
ret
fn4(int, int): # @fn4(int, int)
movsxd rax, edi
imul rcx, rax, 715827883
mov rdx, rcx
shr rdx, 63
shr rcx, 32
add ecx, edx
add ecx, ecx
lea ecx, [rcx + 2*rcx]
sub eax, ecx
cdqe
imul rax, rax, 954437177
mov rcx, rax
shr rcx, 63
sar rax, 33
add eax, ecx
add eax, esi
ret
fn5(int): # @fn5(int)
lea ecx, [rdi + 1]
xor eax, eax
cmp ecx, 2
ja .LBB4_2
movsxd rax, edi
imul rax, rax, 1374389535
mov rcx, rax
shr rcx, 63
sar rax, 37
add eax, ecx
.LBB4_2:
ret
fn6(int, int): # @fn6(int, int)
cmp edi, 1
mov ecx, 7
sbb ecx, 0
mov eax, 4
xor edx, edx
div ecx
mov eax, edx
ret
fn7(int, int): # @fn7(int, int)
mov ecx, 5
mov eax, 5
xor edx, edx
idiv esi
cmp edx, 8
cmova ecx, edi
mov eax, ecx
ret
See it live: <a href="https://godbolt.org/g/JwkE2Z">https://godbolt.org/g/JwkE2Z</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>