Missed optimisation to take advantage of commutative SVE fmul instruction
Example AArch64 SVE intrinsics code:
#include <arm_sve.h>
svfloat64_t svmul_x_2(svfloat64_t x, svfloat64_t y, svbool_t pg)
{
return svmul_x(pg, svdup_f64(2), x);
}
This can generate just a single FMUL instruction but LLVM moves the immediate 2 into a register first. https://godbolt.org/z/11aEEGoce
@llvm/issue-subscribers-backend-aarch64
Author: Kyrill Tkachov (ktkachov)
svfloat64_t svmul_x_2(svfloat64_t x, svfloat64_t y, svbool_t pg) { return svmul_x(pg, svdup_f64(2), x); }
This can generate just a singly FMUL instruction but LLVM moves the immediate 2 into a register first.
https://godbolt.org/z/11aEEGoce
</details>
For input values #0.5 and #2.0, GCC generates the merged form of FMUL instruction as reported in this issue.
@ktkachov , is there a perf penalty of not doing this optimization? Any measurements you have on the same? Thanks
For 2.0 I'm not sure why we would not want to just use an add instead.
@ktkachov , is there a perf penalty of not doing this optimization? Any measurements you have on the same? Thanks
It helps avoid the need for the fmov 0.5 and might save a register, but otherwise should be similar.
It helps avoid the need for the
fmov 0.5and might save a register, but otherwise should be similar.
Yes, I see that benefit. Thank you.
Fixed by https://github.com/llvm/llvm-project/pull/134116. Whilst the PR is specific to multiply instructions, the intent is to expand the coverage to all the operations that can use the existing IR simplification logic.