From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 86285 invoked by alias); 30 Oct 2019 14:29:33 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 86088 invoked by uid 89); 30 Oct 2019 14:29:33 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-7.5 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy=prefers X-HELO: mail-lf1-f53.google.com Received: from mail-lf1-f53.google.com (HELO mail-lf1-f53.google.com) (209.85.167.53) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 30 Oct 2019 14:29:32 +0000 Received: by mail-lf1-f53.google.com with SMTP id v4so1712957lfd.11 for ; Wed, 30 Oct 2019 07:29:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=FccUOoXHoSizbwleMVgt+nGlWich2UfPsuVge7OEUV0=; b=P71QgiOKeh7wEobKm8bnzmDyIKU5AGTYlJYCLpEO4LsogTqhstn2y+iZ59M4IGRXn3 s8zwOLWVjc3Oz81HFtNU9KX2vFdFExIaSQz5B4NlXoA/R1FHLPToXiWwks6Ej+B5NpRe FM1Icap/YBGx85LOU/04E3yXvF+bld6ZnZ/F2XqCngnygXWIeNxXg9SIt9x73fkM+MQR fD643eVxNV1PEvYGRcycs7w3dHl/RKclorSRDQkzhNhmpq6jxISuNjn6mGFG3O+OqGr+ J3ZP9yG7Fwzc/c9Mo/hcdvB7BY+ojmmmXMSYa6+XhwdPYTkh7XDdxWdSNJIBl+Z3EQQ6 Zh1A== MIME-Version: 1.0 References: In-Reply-To: From: Richard Biener Date: Wed, 30 Oct 2019 14:32:00 -0000 Message-ID: Subject: Re: [6/n] Use build_vector_type_for_mode in get_vectype_for_scalar_type_and_size To: Richard Sandiford Cc: GCC Patches Content-Type: text/plain; charset="UTF-8" X-IsSubscribed: yes X-SW-Source: 2019-10/txt/msg02137.txt.bz2 On Fri, Oct 25, 2019 at 2:32 PM Richard Sandiford wrote: > > Except for one case, get_vectype_for_scalar_type_and_size calculates > what the vector mode should be and then calls build_vector_type, > which recomputes the mode from scratch. This patch makes it use > build_vector_type_for_mode instead. > > The exception mentioned above is when preferred_simd_mode returns > an integer mode, which it does if no appropriate vector mode exists. > The integer mode in question is usually word_mode, although epiphany > can return a doubleword mode in some cases. > > There's no guarantee that this integer mode is appropriate, since for > example the scalar type could be a float. The traditional behaviour is > therefore to use the integer mode to determine a size only, and leave > mode_for_vector to pick the TYPE_MODE. (Note that it can actually end > up picking a vector mode if the target defines a disabled vector mode. > We therefore still need to check TYPE_MODE after building the type.) OK. Thanks, Richard. > > 2019-10-24 Richard Sandiford > > gcc/ > * tree-vect-stmts.c (get_vectype_for_scalar_type_and_size): If > targetm.vectorize.preferred_simd_mode returns an integer mode, > use mode_for_vector to decide what the vector type's mode > should actually be. Use build_vector_type_for_mode instead > of build_vector_type. > > Index: gcc/tree-vect-stmts.c > =================================================================== > --- gcc/tree-vect-stmts.c 2019-10-25 13:26:59.309877555 +0100 > +++ gcc/tree-vect-stmts.c 2019-10-25 13:27:08.653811531 +0100 > @@ -11162,16 +11162,31 @@ get_vectype_for_scalar_type_and_size (tr > /* If no size was supplied use the mode the target prefers. Otherwise > lookup a vector mode of the specified size. */ > if (known_eq (size, 0U)) > - simd_mode = targetm.vectorize.preferred_simd_mode (inner_mode); > + { > + simd_mode = targetm.vectorize.preferred_simd_mode (inner_mode); > + if (SCALAR_INT_MODE_P (simd_mode)) > + { > + /* Traditional behavior is not to take the integer mode > + literally, but simply to use it as a way of determining > + the vector size. It is up to mode_for_vector to decide > + what the TYPE_MODE should be. > + > + Note that nunits == 1 is allowed in order to support single > + element vector types. */ > + if (!multiple_p (GET_MODE_SIZE (simd_mode), nbytes, &nunits) > + || !mode_for_vector (inner_mode, nunits).exists (&simd_mode)) > + return NULL_TREE; > + } > + } > else if (!multiple_p (size, nbytes, &nunits) > || !mode_for_vector (inner_mode, nunits).exists (&simd_mode)) > return NULL_TREE; > - /* NOTE: nunits == 1 is allowed to support single element vector types. */ > - if (!multiple_p (GET_MODE_SIZE (simd_mode), nbytes, &nunits)) > - return NULL_TREE; > > - vectype = build_vector_type (scalar_type, nunits); > + vectype = build_vector_type_for_mode (scalar_type, simd_mode); > > + /* In cases where the mode was chosen by mode_for_vector, check that > + the target actually supports the chosen mode, or that it at least > + allows the vector mode to be replaced by a like-sized integer. */ > if (!VECTOR_MODE_P (TYPE_MODE (vectype)) > && !INTEGRAL_MODE_P (TYPE_MODE (vectype))) > return NULL_TREE;