-
- Downloads
SVE intrinsics: Fold svmul by -1 to svneg for unsigned types
As follow-up to https://gcc.gnu.org/pipermail/gcc-patches/2024-October/665472.html , this patch implements folding of svmul by -1 to svneg for unsigned SVE vector types. The key idea is to reuse the existing code that does this fold for signed types and feed it as callback to a helper function that adds the necessary type conversions. For example, for the test case svuint64_t foo (svuint64_t x, svbool_t pg) { return svmul_n_u64_x (pg, x, -1); } the following gimple sequence is emitted (-O2 -mcpu=grace): svuint64_t foo (svuint64_t x, svbool_t pg) { svint64_t D.12921; svint64_t D.12920; svuint64_t D.12919; D.12920 = VIEW_CONVERT_EXPR<svint64_t>(x); D.12921 = svneg_s64_x (pg, D.12920); D.12919 = VIEW_CONVERT_EXPR<svuint64_t>(D.12921); goto <D.12922>; <D.12922>: return D.12919; } In general, the new helper gimple_folder::convert_and_fold - takes a target type and a function pointer, - converts the lhs and all non-boolean vector types to the target type, - passes the converted lhs and arguments to the callback, - receives the new gimple statement from the callback function, - adds the necessary view converts to the gimple sequence, - and returns the new call. Because all arguments are converted to the same target types, the helper function is only suitable for folding calls whose arguments are all of the same type. If necessary, this could be extended to convert the arguments to different types differentially. The patch was bootstrapped and tested on aarch64-linux-gnu, no regression. OK for mainline? Signed-off-by:Jennifer Schmitz <jschmitz@nvidia.com> gcc/ChangeLog: * config/aarch64/aarch64-sve-builtins-base.cc (svmul_impl::fold): Wrap code for folding to svneg in lambda function and pass to gimple_folder::convert_and_fold to enable the transform for unsigned types. * config/aarch64/aarch64-sve-builtins.cc (gimple_folder::convert_and_fold): New function that converts operands to target type before calling callback function, adding the necessary conversion statements. (gimple_folder::redirect_call): Set fntype of redirected call. (get_vector_type): Move from here to aarch64-sve-builtins.h. * config/aarch64/aarch64-sve-builtins.h (gimple_folder::convert_and_fold): Declare function. (get_vector_type): Move here as inline function. gcc/testsuite/ChangeLog: * gcc.target/aarch64/sve/acle/asm/mul_u8.c: Adjust expected outcome. * gcc.target/aarch64/sve/acle/asm/mul_u16.c: Likewise. * gcc.target/aarch64/sve/acle/asm/mul_u32.c: Likewise. * gcc.target/aarch64/sve/acle/asm/mul_u64.c: New test and adjust expected outcome.
Showing
- gcc/config/aarch64/aarch64-sve-builtins-base.cc 35 additions, 21 deletionsgcc/config/aarch64/aarch64-sve-builtins-base.cc
- gcc/config/aarch64/aarch64-sve-builtins.cc 41 additions, 8 deletionsgcc/config/aarch64/aarch64-sve-builtins.cc
- gcc/config/aarch64/aarch64-sve-builtins.h 10 additions, 0 deletionsgcc/config/aarch64/aarch64-sve-builtins.h
- gcc/testsuite/gcc.target/aarch64/sve/acle/asm/mul_u16.c 2 additions, 3 deletionsgcc/testsuite/gcc.target/aarch64/sve/acle/asm/mul_u16.c
- gcc/testsuite/gcc.target/aarch64/sve/acle/asm/mul_u32.c 2 additions, 3 deletionsgcc/testsuite/gcc.target/aarch64/sve/acle/asm/mul_u32.c
- gcc/testsuite/gcc.target/aarch64/sve/acle/asm/mul_u64.c 23 additions, 3 deletionsgcc/testsuite/gcc.target/aarch64/sve/acle/asm/mul_u64.c
- gcc/testsuite/gcc.target/aarch64/sve/acle/asm/mul_u8.c 3 additions, 4 deletionsgcc/testsuite/gcc.target/aarch64/sve/acle/asm/mul_u8.c
Loading
Please register or sign in to comment