From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 C8B7E3856DC0 for ; Fri, 21 Oct 2022 13:19:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C8B7E3856DC0 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666358385; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UN4jxrvaHHGBN9E2j0kx1eNCzW4iTHwv5+vCAexwAXs=; b=OvS1L1suViItSUAJnnTWOrwAIYLhGcKNWBpLA5hOwXZ79Hr7B2oQb9PMJgu2HLNOzasSbt jNB9iDgX7/4th9BHy4ZAJ/p+5cVnfume2nGfQ3wpDRhqVClM0YK77nJxe3nH/a3NBDLy+0 L6LEbpSDNROD2GtNA7RqSlDNh4xbOzU= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-36-8SkbUVrXMJiqCibK09GzbQ-1; Fri, 21 Oct 2022 09:19:35 -0400 X-MC-Unique: 8SkbUVrXMJiqCibK09GzbQ-1 Received: by mail-qk1-f197.google.com with SMTP id u9-20020a05620a454900b006eeafac8ea4so3465802qkp.19 for ; Fri, 21 Oct 2022 06:19:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=UN4jxrvaHHGBN9E2j0kx1eNCzW4iTHwv5+vCAexwAXs=; b=e4KFb9C4AqfZaNoiA4NI5p0cbpyzqTTG19oF9YYDhI8+TBgzDzmQwx444W3GZ57Z+T qHuJrra9AMSc8968mHk6ZNV3E068wSr4HoQhWQJDhPlZ9F819/MKUzZBMCNHzutYZkP5 59wbcuPHhkCXgXi0Sb14KVePWdMmnM3jfR17+XhiQwTgTNjfsAABOc/+uMSgfRxFQtZ5 nIuz7YRbWO5cyCiJL6IVxrt7KhcPkF6wOBTdh9z0WsT4Pgu6StATyH6Pz8cmbsBJr3Je KSCm47eIHIKFM7sNC3M76Hgx7oKujhG86N9okvRRgRQIoAPzmL4z+iXQtYfEU5Ry9M3x tI2A== X-Gm-Message-State: ACrzQf0XE48W0hy0mcNRhS+OEzFOP+Qbkmd3JQk9CnuBnXzYL2bs2SFM /CHPG3aCnRTCWKxDrfxsxxQHOBwsFzPbelBaIAT4E47fZJmrW4qz0QDTohsUwbQMhGiopAgq5Jc cYLnGUOow5qVIrgcYLQ== X-Received: by 2002:a05:6214:3017:b0:4b3:cefd:fad5 with SMTP id ke23-20020a056214301700b004b3cefdfad5mr16776990qvb.37.1666358374740; Fri, 21 Oct 2022 06:19:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5YITCUJqoRqZ9Pmt3aDZHmgumjQUDI3WYJuLRqz/srwBFTPrSEuLQCE24D2RgyqTt3avAqxA== X-Received: by 2002:a05:6214:3017:b0:4b3:cefd:fad5 with SMTP id ke23-20020a056214301700b004b3cefdfad5mr16776965qvb.37.1666358374389; Fri, 21 Oct 2022 06:19:34 -0700 (PDT) Received: from [192.168.1.101] (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id i9-20020ac85c09000000b0039a610a04b1sm8120680qti.37.2022.10.21.06.19.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 21 Oct 2022 06:19:33 -0700 (PDT) Message-ID: <1a28849d-b23c-e70c-27f3-b0bd3c48c269@redhat.com> Date: Fri, 21 Oct 2022 09:19:32 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.2 Subject: Re: [PATCH] c++, v2: Don't shortcut TREE_CONSTANT vector type CONSTRUCTORs in cxx_eval_constant_expression [PR107295] To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org References: From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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 10/21/22 03:30, Jakub Jelinek wrote: > On Thu, Oct 20, 2022 at 10:51:14AM -0400, Jason Merrill wrote: >> That seems like a bug; for VECTOR_TYPE we should fold even if !changed. >> >>> Also, the reason for the short-cutting is I think trying to avoid >>> allocating a new CONSTRUCTOR when nothing changes and we just create >>> GC garbage by it. >> >> We might limit the shortcut to non-vector types by hoisting the vector check >> in reduced_constant_expression_p out of the CONSTRUCTOR_NO_CLEARING >> condition: >> >>> if (CONSTRUCTOR_NO_CLEARING (t)) >>> { >>> if (TREE_CODE (TREE_TYPE (t)) == VECTOR_TYPE) >>> /* An initialized vector would have a VECTOR_CST. */ >>> return false; >> >> then we could remove the fold in the shortcut. > > Ok, so like this? > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? OK. > 2022-10-21 Jakub Jelinek > > PR c++/107295 > * constexpr.cc (reduced_constant_expression_p) : > Return false for VECTOR_TYPE CONSTRUCTORs even without > CONSTRUCTOR_NO_CLEARING set on them. > (cxx_eval_bare_aggregate): If constant but !changed, fold before > returning VECTOR_TYPE_P CONSTRUCTOR. > (cxx_eval_constant_expression) : Don't fold > TREE_CONSTANT CONSTRUCTOR, just return it. > > * g++.dg/ext/vector42.C: New test. > > --- gcc/cp/constexpr.cc.jj 2022-10-19 11:20:28.960225787 +0200 > +++ gcc/cp/constexpr.cc 2022-10-20 18:43:42.952440364 +0200 > @@ -3104,12 +3104,12 @@ reduced_constant_expression_p (tree t) > case CONSTRUCTOR: > /* And we need to handle PTRMEM_CST wrapped in a CONSTRUCTOR. */ > tree field; > + if (TREE_CODE (TREE_TYPE (t)) == VECTOR_TYPE) > + /* An initialized vector would have a VECTOR_CST. */ > + return false; > if (CONSTRUCTOR_NO_CLEARING (t)) > { > - if (TREE_CODE (TREE_TYPE (t)) == VECTOR_TYPE) > - /* An initialized vector would have a VECTOR_CST. */ > - return false; > - else if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE) > + if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE) > { > /* There must be a valid constant initializer at every array > index. */ > @@ -4956,8 +4956,14 @@ cxx_eval_bare_aggregate (const constexpr > TREE_SIDE_EFFECTS (ctx->ctor) = side_effects_p; > } > } > - if (*non_constant_p || !changed) > + if (*non_constant_p) > return t; > + if (!changed) > + { > + if (VECTOR_TYPE_P (type)) > + t = fold (t); > + return t; > + } > t = ctx->ctor; > if (!t) > t = build_constructor (type, NULL); > @@ -7387,11 +7393,10 @@ cxx_eval_constant_expression (const cons > case CONSTRUCTOR: > if (TREE_CONSTANT (t) && reduced_constant_expression_p (t)) > { > - /* Don't re-process a constant CONSTRUCTOR, but do fold it to > - VECTOR_CST if applicable. */ > + /* Don't re-process a constant CONSTRUCTOR. */ > verify_constructor_flags (t); > if (TREE_CONSTANT (t)) > - return fold (t); > + return t; > } > r = cxx_eval_bare_aggregate (ctx, t, lval, > non_constant_p, overflow_p); > --- gcc/testsuite/g++.dg/ext/vector42.C.jj 2022-10-20 17:57:42.767848544 +0200 > +++ gcc/testsuite/g++.dg/ext/vector42.C 2022-10-20 17:57:42.767848544 +0200 > @@ -0,0 +1,12 @@ > +// PR c++/107295 > +// { dg-do compile { target c++11 } } > + > +template struct A { > + typedef T __attribute__((vector_size (sizeof (int)))) V; > +}; > +template using B = typename A::V; > +template using V = B<4, T>; > +using F = V; > +constexpr F a = F () + 0.0f; > +constexpr F b = F () + (float) 0.0; > +constexpr F c = F () + (float) 0.0L; > > > Jakub >