From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2017) id 9F0A9385842A; Mon, 23 Oct 2023 16:44:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9F0A9385842A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1698079455; bh=mWORYP6CAEbKBPgMSJmn/I4f1dQVdFc2iAKDi3kQv9Y=; h=From:To:Subject:Date:From; b=cDDpbfMUy7xK/9CoEUu+VVJR7NUGV/iKMFKZ+F0UZ5Eli/KUyPFmse2eVn38YKJC3 1z4zKLnkRPyzlTWnhfMz25BhFL9D+hQ1YMPsX9W8xvDyRQUwVs8zj6eqLOQdEH+lvS gT5EPY1InitWWeqPFI76KtKGQnkBW4Ac0jzelKcc= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Robin Dapp To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-4868] vect: Allow same precision for bit-precision conversions. X-Act-Checkin: gcc X-Git-Author: Robin Dapp X-Git-Refname: refs/heads/master X-Git-Oldrev: 82bbbb73c67f79582d38a1aa63984987dcd0923a X-Git-Newrev: 32b74c9e1d46932a4bbb1f46353bfc43c702c20a Message-Id: <20231023164415.9F0A9385842A@sourceware.org> Date: Mon, 23 Oct 2023 16:44:15 +0000 (GMT) List-Id: https://gcc.gnu.org/g:32b74c9e1d46932a4bbb1f46353bfc43c702c20a commit r14-4868-g32b74c9e1d46932a4bbb1f46353bfc43c702c20a Author: Robin Dapp Date: Sun Oct 15 22:36:59 2023 +0200 vect: Allow same precision for bit-precision conversions. In PR111794 we miss a vectorization because on riscv type precision and mode precision differ for mask types. We can still vectorize when allowing assignments with the same precision for dest and source which is what this patch does. gcc/ChangeLog: PR tree-optimization/111794 * tree-vect-stmts.cc (vectorizable_assignment): Add same-precision exception for dest and source. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/autovec/slp-mask-1.c: New test. * gcc.target/riscv/rvv/autovec/slp-mask-run-1.c: New test. Diff: --- .../gcc.target/riscv/rvv/autovec/slp-mask-1.c | 18 +++++++++++++ .../gcc.target/riscv/rvv/autovec/slp-mask-run-1.c | 31 ++++++++++++++++++++++ gcc/tree-vect-stmts.cc | 12 +++++---- 3 files changed, 56 insertions(+), 5 deletions(-) diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/slp-mask-1.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/slp-mask-1.c new file mode 100644 index 000000000000..ee1baa58d634 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/slp-mask-1.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-std=gnu99 -O3 -march=rv64gcv -mabi=lp64d --param=riscv-autovec-preference=scalable -fdump-tree-slp-details" } */ + +void +__attribute__ ((noipa)) +f (int *restrict x, short *restrict y, int *restrict res) +{ + res[0] = x[0] == 1 & y[0] == 2; + res[1] = x[1] == 1 & y[1] == 2; + res[2] = x[2] == 1 & y[2] == 2; + res[3] = x[3] == 1 & y[3] == 2; + res[4] = x[4] == 1 & y[4] == 2; + res[5] = x[5] == 1 & y[5] == 2; + res[6] = x[6] == 1 & y[6] == 2; + res[7] = x[7] == 1 & y[7] == 2; +} + +/* { dg-final { scan-tree-dump-times "vectorizing stmts using SLP" 1 "slp2" } } */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/slp-mask-run-1.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/slp-mask-run-1.c new file mode 100644 index 000000000000..b3469c41c878 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/slp-mask-run-1.c @@ -0,0 +1,31 @@ +/* { dg-do run { target { riscv_v } } } */ +/* { dg-additional-options "-std=gnu99 -O3 -march=rv64gcv -mabi=lp64d --param=riscv-autovec-preference=scalable" } */ + +#include +#include + +#include "slp-mask-1.c" + +#define SZ 8 + +__attribute__ ((optimize ("1"))) +int main () +{ + int *a = malloc (SZ * sizeof (*a)); + short *b = malloc (SZ * sizeof (*b)); + int *res = malloc (SZ * sizeof (*res)); + int *ref = malloc (SZ * sizeof (*ref)); + + for (int i = 0; i < SZ; i++) + { + a[i] = i & 1; + b[i] = 2; + ref[i] = a[i] == 1 & b[i] == 2; + } + + f (a, b, res); + + for (int i = 0; i < SZ; i++) + if (res[i] != ref[i]) + __builtin_abort (); +} diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc index 99ba75e98c0d..a9200767f67a 100644 --- a/gcc/tree-vect-stmts.cc +++ b/gcc/tree-vect-stmts.cc @@ -6058,14 +6058,16 @@ vectorizable_assignment (vec_info *vinfo, /* But a conversion that does not change the bit-pattern is ok. */ && !(INTEGRAL_TYPE_P (TREE_TYPE (scalar_dest)) && INTEGRAL_TYPE_P (TREE_TYPE (op)) - && (TYPE_PRECISION (TREE_TYPE (scalar_dest)) + && (((TYPE_PRECISION (TREE_TYPE (scalar_dest)) > TYPE_PRECISION (TREE_TYPE (op))) - && TYPE_UNSIGNED (TREE_TYPE (op)))) + && TYPE_UNSIGNED (TREE_TYPE (op))) + || (TYPE_PRECISION (TREE_TYPE (scalar_dest)) + == TYPE_PRECISION (TREE_TYPE (op)))))) { if (dump_enabled_p ()) - dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, - "type conversion to/from bit-precision " - "unsupported.\n"); + dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, + "type conversion to/from bit-precision " + "unsupported.\n"); return false; }