[llvm-bugs] [Bug 35604] New: Missed optimization in math expression: sqrt(a) * sqrt(b) == sqrt(a*b)
via llvm-bugs
llvm-bugs at lists.llvm.org
Sun Dec 10 08:05:37 PST 2017
https://bugs.llvm.org/show_bug.cgi?id=35604
Bug ID: 35604
Summary: Missed optimization in math expression: sqrt(a) *
sqrt(b) == sqrt(a*b)
Product: libraries
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: enhancement
Priority: P
Component: Common Code Generator Code
Assignee: unassignedbugs at nondot.org
Reporter: zamazan4ik at tut.by
CC: llvm-bugs at lists.llvm.org
clang(trunk) with '--std=c++17 -O3 -march=native -ffast-math' flags for this
code:
#include <cmath>
double test(double a, double b)
{
return sqrt(a) * sqrt(b);
}
generates this assembly:
test(double, double, double): # @test(double, double, double)
vsqrtsd xmm0, xmm0, xmm0
vsqrtsd xmm1, xmm1, xmm1
vmulsd xmm0, xmm1, xmm0
ret
gcc(trunk) with '--std=c++17 -O3 -march=native -ffast-math' flags generates
this:
test(double, double, double):
vmulsd xmm0, xmm0, xmm1
vsqrtsd xmm0, xmm0, xmm0
ret
Also if you will increase count of multiplication on sqrt(varible_name), gcc
continues generate more optimal code:
#include <cmath>
double test(double a, double b, double c)
{
return sqrt(a) * sqrt(b) * sqrt(c);
}
clang:
test(double, double, double): # @test(double, double, double)
vsqrtsd xmm0, xmm0, xmm0
vsqrtsd xmm1, xmm1, xmm1
vmulsd xmm0, xmm1, xmm0
vsqrtsd xmm1, xmm2, xmm2
vmulsd xmm0, xmm0, xmm1
ret
gcc:
test(double, double, double):
vmulsd xmm2, xmm1, xmm2
vmulsd xmm0, xmm2, xmm0
vsqrtsd xmm0, xmm0, xmm0
ret
--
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/20171210/b3f882d2/attachment.html>
More information about the llvm-bugs
mailing list