From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) by sourceware.org (Postfix) with ESMTPS id 41CB43858D32 for ; Mon, 13 Mar 2023 09:08:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 41CB43858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-x22d.google.com with SMTP id t14so11833229ljd.5 for ; Mon, 13 Mar 2023 02:08:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678698529; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=vCFqz4k+0GzSVEhiF+k838g9YzJR6kTABfa9Z/vIM2Q=; b=R6gbIJChftK7IKfvIoNyCDTl1crQi27wuGUgJjr6tYYDiGPMudWrW2XVrUTBL4DiXQ pylp5oheR+kkLUOOinGVhIg91A1QNSaN8+FqlyHNqBIQPpEtgsaEpfFwK3a8c+t1GDAl z4jg7dGcb2t6x3CnwDKwZ/4rXOnflNRTr7+eaihSUVdgFhmun0VweqmK+UJD2UwTZrgF L1N8Re9mYCDZnBzzYQu37zAD5NXgSPstFcUXpkyoitsn5C0J15N0DqUHh7HHnYUuzJ7f M4ndJ+xMhUKUwYDnp/ETRdL/LJt/0uRto477v5n2yIqBI3JcqG/m+m7MK7rc+sWr51/i 13Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678698529; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vCFqz4k+0GzSVEhiF+k838g9YzJR6kTABfa9Z/vIM2Q=; b=nCm/ynQ3wPV6M3qDJJsk8zbdY8lKt99WBtvlYMt9ZlRVnjzBXhuhPwIDoLChs1VB+G bNIdLHPw+89SQIy0J7kI34LPUK+2Pv0W0ElL+4M8s3my6AUDV9jXCPGWnU1WNhQj34Mk U7oIfz8ovimEVuesxRSqzh/9fmRCoz58oAnJ9jRDJScPpniDRNh89FHRhGKJN0PHg4Vo nCJLwFbS2lD8qPo/cR9ObEjbElhZpafHtAvWjDhI6Ix3Vdgm1oXtPa7kqK/lqJKTQMiR dEVqelMMk7pfKDjCcSyZmwsmHVx9XenIWv3aPntZFVPZsPgrNM6pxJk83sD1q5O3fDbQ TDww== X-Gm-Message-State: AO0yUKUuzVlzc01PYI/qalbehyGNCNWXyyRR81SUMrXlALIkp8Z9R/X/ RMqkuvjdu1PFU0iWjK2S/YHFZf1pBvReBXEFZug= X-Google-Smtp-Source: AK7set/UscQbkMkiohgclaGAPbkEsxdtCRutb7IjkcYoXI5xJvwM/o0i2uPfQu6mhcBKGmBKBYzA7xbfdZtdL0STH3I= X-Received: by 2002:a05:651c:1727:b0:295:a446:cd05 with SMTP id be39-20020a05651c172700b00295a446cd05mr10280253ljb.6.1678698529420; Mon, 13 Mar 2023 02:08:49 -0700 (PDT) MIME-Version: 1.0 References: <20230310201620.2097011-1-collison@rivosinc.com> In-Reply-To: <20230310201620.2097011-1-collison@rivosinc.com> From: Richard Biener Date: Mon, 13 Mar 2023 10:08:28 +0100 Message-ID: Subject: Re: [PATCH] vect: Verify that GET_MODE_NUNITS is power-of-2 To: Michael Collison Cc: gcc-patches@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,KAM_NUMSUBJECT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Fri, Mar 10, 2023 at 9:16=E2=80=AFPM Michael Collison wrote: > > While working on autovectorizing for the RISCV port I encountered an issu= e > where can_duplicate_and_interleave_p assumes that GET_MODE_NUNITS is a > power of two. The RISC-V target has vector modes (e.g. VNx1DImode) that > are not a power of two. We do not support vector types that do not have a power-of-two element count, see TYPE_VECTOR_SUBPARTS. Also your test below verifies that nunits is divisible by two, not that it is power-of-two? So maybe what you want to know is whether known_gt (nunits, 1)? > Tested on RISCV and x86_64-linux-gnu. Okay? > > 2023-03-09 Michael Collison > > * poly-int.h (exact_div_p): New function to > verify that argument is a power of 2 poly_int. > * tree-vect-slp.cc (can_duplicate_and_interleave_p): > Check that GET_MODE_NUNITS is a power of 2. > --- > gcc/poly-int.h | 17 +++++++++++++++++ > gcc/tree-vect-slp.cc | 3 ++- > 2 files changed, 19 insertions(+), 1 deletion(-) > > diff --git a/gcc/poly-int.h b/gcc/poly-int.h > index 12571455081..d09632f341f 100644 > --- a/gcc/poly-int.h > +++ b/gcc/poly-int.h > @@ -2219,6 +2219,23 @@ multiple_p (const poly_int_pod &a, const po= ly_int_pod &b, > return constant_multiple_p (a, b, multiple); > } > > +/* Return true, if A is known to be a multiple of B. */ > + > +template > +inline bool > +exact_div_p (const poly_int_pod &a, Cb b) > +{ > + typedef POLY_CONST_COEFF (Ca, Cb) C; > + poly_int r; > + for (unsigned int i =3D 0; i < N; i++) > + { > + if ((a.coeffs[i] % b) !=3D 0) > + return false; > + > + } > + return true; > +} > + > /* Return A / B, given that A is known to be a multiple of B. */ > > template > diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc > index 9a4e000925e..6be2036a13a 100644 > --- a/gcc/tree-vect-slp.cc > +++ b/gcc/tree-vect-slp.cc > @@ -426,7 +426,8 @@ can_duplicate_and_interleave_p (vec_info *vinfo, unsi= gned int count, > if (vector_type > && VECTOR_MODE_P (TYPE_MODE (vector_type)) > && known_eq (GET_MODE_SIZE (TYPE_MODE (vector_type)), > - GET_MODE_SIZE (base_vector_mode))) > + GET_MODE_SIZE (base_vector_mode)) > + && exact_div_p (GET_MODE_NUNITS (TYPE_MODE (vector_type)), = 2)) > { > /* Try fusing consecutive sequences of COUNT / NVECTORS ele= ments > together into elements of type INT_TYPE and using the re= sult > -- > 2.34.1 >