[llvm-bugs] [Bug 46599] New: Commutable subtractions
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Jul 6 04:47:40 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=46599
Bug ID: 46599
Summary: Commutable subtractions
Product: libraries
Version: trunk
Hardware: PC
OS: Windows NT
Status: NEW
Severity: enhancement
Priority: P
Component: Common Code Generator Code
Assignee: unassignedbugs at nondot.org
Reporter: llvm-dev at redking.me.uk
CC: craig.topper at gmail.com, efriedma at quicinc.com,
lebedev.ri at gmail.com, llvm-bugs at lists.llvm.org,
spatel+llvm at rotateright.com
If a subtraction result is only ever used for certain instructions (f)abs,
(f)mul etc. we might be able to tag the subtraction as "commutable".
This is particularly interesting for SSE memory folding (either direct or via
folding stack operations):
https://godbolt.org/z/zkELgP
#include <x86intrin.h>
auto dp_offset(__m128 *x, __m128 *y, __m128 z, __m128 w) {
__m128 xx = _mm_sub_ps(*x, z);
__m128 yy = _mm_sub_ps(*y, w);
return _mm_add_ps(
_mm_mul_ps(xx, xx),
_mm_mul_ps(yy, yy)
);
}
auto dp_offset_commute(__m128 *x, __m128 *y, __m128 z, __m128 w) {
__m128 xx = _mm_sub_ps(z, *x);
__m128 yy = _mm_sub_ps(w, *y);
return _mm_add_ps(
_mm_mul_ps(xx, xx),
_mm_mul_ps(yy, yy)
);
}
clang -g0 -O3 -march=btver2
dp_offset:
vmovaps (%rdi), %xmm2
vmovaps (%rsi), %xmm3
vsubps %xmm0, %xmm2, %xmm0
vsubps %xmm1, %xmm3, %xmm1
vmulps %xmm0, %xmm0, %xmm0
vmulps %xmm1, %xmm1, %xmm1
vaddps %xmm1, %xmm0, %xmm0
retq
dp_offset_commute:
vsubps (%rdi), %xmm0, %xmm0
vsubps (%rsi), %xmm1, %xmm1
vmulps %xmm0, %xmm0, %xmm0
vmulps %xmm1, %xmm1, %xmm1
vaddps %xmm1, %xmm0, %xmm0
retq
--
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/20200706/afb7d622/attachment.html>
More information about the llvm-bugs
mailing list