[llvm-bugs] [Bug 34517] New: Missed optimizations due to incomplete range analysis
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Sep 7 05:58:52 PDT 2017
https://bugs.llvm.org/show_bug.cgi?id=34517
Bug ID: 34517
Summary: Missed optimizations due to incomplete range analysis
Product: clang
Version: trunk
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P
Component: -New Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: gonzalobg88 at gmail.com
CC: llvm-bugs at lists.llvm.org
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: https://godbolt.org/g/JwkE2Z
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170907/15370dd7/attachment.html>
More information about the llvm-bugs
mailing list