[llvm-bugs] [Bug 42716] New: Optimize lerp with two FMAs
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Jul 22 10:43:49 PDT 2019
https://bugs.llvm.org/show_bug.cgi?id=42716
Bug ID: 42716
Summary: Optimize lerp with two FMAs
Product: libraries
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: Scalar Optimizations
Assignee: unassignedbugs at nondot.org
Reporter: david.bolvansky at gmail.com
CC: llvm-bugs at lists.llvm.org
Tip from: https://devblogs.nvidia.com/lerp-faster-cuda/
float lerp(float a, float b, float c) {
return (1-c)*a +c*b;
}
float lerp2(float a, float b, float c)
{
return a + c * (b - a);
}
float rf2(float a, float b, float c) {
return std::fma(c, b, std::fma(-c, a, a));
}
Clang trunk -Ofast -std=c++17 -mfma
lerp(float, float, float): # @lerp(float, float,
float)
vmovss xmm3, dword ptr [rip + .LCPI0_0] # xmm3 = mem[0],zero,zero,zero
vsubss xmm3, xmm3, xmm2
vmulss xmm1, xmm2, xmm1
vfmadd213ss xmm0, xmm3, xmm1 # xmm0 = (xmm3 * xmm0) + xmm1
ret
lerp2(float, float, float): # @lerp2(float, float,
float)
vsubss xmm1, xmm1, xmm0
vfmadd231ss xmm0, xmm2, xmm1 # xmm0 = (xmm2 * xmm1) + xmm0
ret
rf2(float, float, float): # @rf2(float, float,
float)
vfnmadd213ss xmm0, xmm2, xmm0 # xmm0 = -(xmm2 * xmm0) + xmm0
vfmadd231ss xmm0, xmm2, xmm1 # xmm0 = (xmm2 * xmm1) + xmm0
ret
InstCombine?
A) Missing fold: (1-c)*a +c*b -> a + c * (b - a)
B) Fold a + c * (b - a) to llvm.fma(c, b, llvm.fma(-c, a, a)) if FMA enabled
--
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/20190722/46e4f6c3/attachment.html>
More information about the llvm-bugs
mailing list