From patchwork Wed Jan 26 09:33:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 50449 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DB663385141D for ; Wed, 26 Jan 2022 09:34:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DB663385141D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1643189679; bh=QqnAxhrjErhYDMQ3Vpj7q4IcZZpErsVQWuSgmaxY9ag=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=rbDwuiIAy4CfvY8vgLgSfeBdRphHr2J9OIzoJRi1gCgPd08v+cJrDVB6w1qjrf17a hlhFGR4wxABFqFfro0PrejUO2/jZmMbuxecwe9wDLD0ziaoFxMxk/rnQ/S3kqco9U/ /BQuI+VqjPmG7dgqu7/cOIOp15IPRrSncamnAsvQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 4AD7A3851C01 for ; Wed, 26 Jan 2022 09:34:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4AD7A3851C01 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-274-z-wVkcPzPNmP2Fja_MMGLQ-1; Wed, 26 Jan 2022 04:34:07 -0500 X-MC-Unique: z-wVkcPzPNmP2Fja_MMGLQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 23A788519E4 for ; Wed, 26 Jan 2022 09:34:06 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.125]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B09B56ABBC; Wed, 26 Jan 2022 09:34:00 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 20Q9XvTA2277717 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 26 Jan 2022 10:33:58 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 20Q9Xvn52277716; Wed, 26 Jan 2022 10:33:57 +0100 Date: Wed, 26 Jan 2022 10:33:57 +0100 To: Jason Merrill Subject: [PATCH] c++: Fix up handling of vector CONSTRUCTORs with vectors in it in constexpr.cc [PR104226] Message-ID: <20220126093357.GQ2646553@tucnak> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi! The middle-end uses sometimes VECTOR_TYPE CONSTRUCTORs that contain some other VECTOR_TYPE elements in it (should be with compatible element size and smaller number of elements, e.g. a V8SImode vector can be constructed as { V4SImode_var_1, V4SImode_var_2 }), and expansion of __builtin_shufflevector emits these early, so constexpr.cc can see those too. constexpr.cc already has special cases for NULL index which is typical for VECTOR_TYPE CONSTRUCTORs, and for VECTOR_TYPE CONSTRUCTORs that contain just scalar elts that works just fine - init_subob_ctx just returns on non-aggregate elts and get_or_insert_ctor_field has if (TREE_CODE (type) == VECTOR_TYPE && index == NULL_TREE) { CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (ctor), index, NULL_TREE); return &CONSTRUCTOR_ELTS (ctor)->last(); } handling for it. But for the vector in vector case init_subob_ctx would try to create a sub-CONSTRUCTOR and even didn't handle the NULL index case well, so instead of creating the sub-CONSTRUCTOR after the elts already in it overwrote the first one. So (V8SImode) { { 0, 0, 0, 0 }, { 0, 0, 0, 0 } } became (V8SImode) { 0, 0, 0, 0 } The following patch fixes it by not forcing a sub-CONSTRUCTOR for this vector in vector case. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2022-01-26 Jakub Jelinek PR c++/104226 * constexpr.cc (init_subob_ctx): For vector ctors containing vector elements, ensure appending to the same ctor instead of creating another one. * g++.dg/cpp0x/constexpr-104226.C: New test. Jakub --- gcc/cp/constexpr.cc.jj 2022-01-19 00:42:11.000000000 +0100 +++ gcc/cp/constexpr.cc 2022-01-25 21:44:28.459208756 +0100 @@ -4658,6 +4658,13 @@ init_subob_ctx (const constexpr_ctx *ctx if (!AGGREGATE_TYPE_P (type) && !VECTOR_TYPE_P (type)) /* A non-aggregate member doesn't get its own CONSTRUCTOR. */ return; + if (VECTOR_TYPE_P (type) + && VECTOR_TYPE_P (TREE_TYPE (ctx->ctor)) + && index == NULL_TREE) + /* A vector inside of a vector CONSTRUCTOR, e.g. when a larger + vector is constructed from smaller vectors, doesn't get its own + CONSTRUCTOR either. */ + return; /* The sub-aggregate initializer might contain a placeholder; update object to refer to the subobject and ctor to refer to --- gcc/testsuite/g++.dg/cpp0x/constexpr-104226.C.jj 2022-01-25 21:50:34.977031244 +0100 +++ gcc/testsuite/g++.dg/cpp0x/constexpr-104226.C 2022-01-25 21:51:41.851086559 +0100 @@ -0,0 +1,15 @@ +// PR c++/104226 +// { dg-do compile } +// { dg-options "-Wno-psabi" } + +typedef unsigned short __attribute__((__vector_size__(16))) U; +typedef unsigned int __attribute__((__vector_size__(16))) V; +typedef unsigned int __attribute__((__vector_size__(32))) W; + +U +foo (void) +{ + return __builtin_convertvector (__builtin_shufflevector ((V){}, (W){}, + 0, 0, 1, 0, + 5, 5, 0, 2), U); +}