Skip to content

[AArch64][SVE] Fold svmul and svdiv with all-zero operands to zero vector #110392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
k-arrows opened this issue Sep 29, 2024 · 2 comments
Closed
Assignees
Labels
backend:AArch64 missed-optimization SVE ARM Scalable Vector Extensions

Comments

@k-arrows
Copy link

k-arrows commented Sep 29, 2024

GCC has implemented this in recent patches. Consider the following example.
https://godbolt.org/z/dPY9f3oxe

#include <arm_sve.h>

svint64_t test1 (svbool_t pg, svint64_t op2)
{
  return svmul_x (pg, svdup_s64 (0), op2);
}

svint64_t test2 (svbool_t pg, svint64_t op2)
{
  return svdiv_x (pg, svdup_s64 (0), op2);
}

GCC:

test1(__SVBool_t, __SVInt64_t):
        mov     z0.b, #0
        ret
test2(__SVBool_t, __SVInt64_t):
        mov     z0.b, #0
        ret

Clang:

test1(__SVBool_t, __SVInt64_t):
        mov     z1.d, #0
        mul     z0.d, p0/m, z0.d, z1.d
        ret

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

I referred to the GCC patch below.
svmul
svdiv

@EugeneZelenko EugeneZelenko added backend:AArch64 SVE ARM Scalable Vector Extensions and removed new issue labels Sep 29, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 29, 2024

@llvm/issue-subscribers-backend-aarch64

Author: None (k-arrows)

GCC has implemented this in recent patches. Consider the following example. https://godbolt.org/z/dPY9f3oxe ```cpp #include <arm_sve.h>

svint64_t test1 (svbool_t pg, svint64_t op2)
{
return svmul_x (pg, svdup_s64 (0), op2);
}

svint64_t test2 (svbool_t pg, svint64_t op2)
{
return svdiv_x (pg, svdup_s64 (0), op2);
}


GCC:
```asm
test1(__SVBool_t, __SVInt64_t):
        mov     z0.b, #<!-- -->0
        ret
test2(__SVBool_t, __SVInt64_t):
        mov     z0.b, #<!-- -->0
        ret

Clang:

test1(__SVBool_t, __SVInt64_t):
        mov     z1.d, #<!-- -->0
        mul     z0.d, p0/m, z0.d, z1.d
        ret

test2(__SVBool_t, __SVInt64_t):
        mov     z1.d, #<!-- -->0
        sdivr   z0.d, p0/m, z0.d, z1.d
        ret

I referred to the GCC patch below.
svmul
svdiv

@paulwalker-arm
Copy link
Collaborator

#134116 introduced general simplification support for SVE intrinsics that have an IR instruction equivalent. The PR only covered mul but has since been extended to cover the majority of binops.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:AArch64 missed-optimization SVE ARM Scalable Vector Extensions
Projects
None yet
Development

No branches or pull requests

4 participants