llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.69k stars 11.86k forks source link

[AArch64][SVE] Fold constant operands for svmul and svdiv #110424

Open k-arrows opened 3 weeks ago

k-arrows commented 3 weeks ago

As with https://github.com/llvm/llvm-project/issues/110392, GCC has implemented this in recent patches. Consider the following example. https://godbolt.org/z/M8Pe1G6Ge

#include <arm_sve.h>

svint64_t test1 (svbool_t pg)
{
  return svmul_x (pg, svdup_s64 (5), svdup_s64 (3));
}

svint64_t test2 (svbool_t pg)
{
  return svdiv_x (pg, svdup_s64 (5), svdup_s64 (3));
}

GCC:

test1(__SVBool_t):
        mov     z0.d, #15
        ret
test2(__SVBool_t):
        mov     z0.d, #1
        ret

Clang:

test1(__SVBool_t):
        mov     z0.d, #5
        mul     z0.d, z0.d, #3
        ret

test2(__SVBool_t):
        mov     z0.d, #3
        mov     z1.d, #5
        sdivr   z0.d, p0/m, z0.d, z1.d
        ret

I referred to the GCC patch below. svmul svdiv

llvmbot commented 3 weeks ago

@llvm/issue-subscribers-backend-aarch64

Author: None (k-arrows)

As with https://github.com/llvm/llvm-project/issues/110392, GCC has implemented this in recent patches. Consider the following example. https://godbolt.org/z/M8Pe1G6Ge ```cpp #include <arm_sve.h> svint64_t test1 (svbool_t pg) { return svmul_x (pg, svdup_s64 (5), svdup_s64 (3)); } svint64_t test2 (svbool_t pg) { return svdiv_x (pg, svdup_s64 (5), svdup_s64 (3)); } ``` GCC: ```asm test1(__SVBool_t): mov z0.d, #15 ret test2(__SVBool_t): mov z0.d, #1 ret ``` Clang: ```asm test1(__SVBool_t): mov z0.d, #5 mul z0.d, z0.d, #3 ret test2(__SVBool_t): mov z0.d, #3 mov z1.d, #5 sdivr z0.d, p0/m, z0.d, z1.d ret ``` I referred to the GCC patch below. [svmul](https://github.com/gcc-mirror/gcc/commit/6b1cf59e90d3d6391d61b2a8f77856b5aa044014) [svdiv](https://github.com/gcc-mirror/gcc/commit/ee8b7231b03a36dfc09d94f2b663636ca2a36daf)