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.129.124]) by sourceware.org (Postfix) with ESMTPS id C092C385086D for ; Thu, 20 Oct 2022 14:51:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C092C385086D 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=1666277489; 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=FpIuQQR84MpZK7ZqkBPtBeQHGK+IdVOXNYR+Ax6h1EE=; b=SnRt4T9GEsEPlm5gujJ+Qk14Bx08u4h7wZ4w4UTZ6ZkWRtWPvWkdtuEo3tSW3x50zv0hXR 0BW2g6RPewSD4wMa2SKp6RTBz1OOOy6FvEooZft0udkv2H5Wz6AIbwlPrsWjtVec+2+Pq2 BjnTjtn3LhwSz5vsrGiFH3bJFfTR2aE= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-35-08AykZr4Nq6sH8rJS9_Xuw-1; Thu, 20 Oct 2022 10:51:16 -0400 X-MC-Unique: 08AykZr4Nq6sH8rJS9_Xuw-1 Received: by mail-qv1-f72.google.com with SMTP id ln3-20020a0562145a8300b004b8c29a7d50so1132807qvb.15 for ; Thu, 20 Oct 2022 07:51:16 -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=FpIuQQR84MpZK7ZqkBPtBeQHGK+IdVOXNYR+Ax6h1EE=; b=hC3OeQzSaQCIs5qe2ZqU2kdsI1avkbyrWw5YJb3b7bnmJ+MYqCQUKKD4JQsMfbGFKB Y52kgtDpVWqqQN3ngMKLTqRaNZQajLQ/XL1w74deRVjuuq0kw62wacwvW10nRVV8qBMi kVemN0IdMkFIlJi7rzfFNX220Cct8YRho45YRkzePC3hZBAMtFK8AmyPoOgrG9l7QrVF npDkyVWKRq+VACwYxKqHp2QhVaufskhPk1UuuTCbxTgbw6uwCs7Tt6gg+/++b+rhSZ7Y FW0+tyanBaSBu7zOoNhMRQTFwf4g/XfvJFa3To36SifuRW9E2FK2Yq0BvXoEa+KH7+4f 6rdg== X-Gm-Message-State: ACrzQf0CHeMDfvl5qci6b6dYT3/j6c4r5iqYVoyBGENl8KFE/OrJsH+d qD8Krv8ORENf2QvWBLmweEtt2F4erNRz84pT7vNzFgBmPegoeZ9Bs4pAExC2t2UmljFKbVU4bjv TQSSjKNwNa/7fMYyo6A== X-Received: by 2002:a37:b586:0:b0:6df:fd18:386d with SMTP id e128-20020a37b586000000b006dffd18386dmr9629294qkf.114.1666277475828; Thu, 20 Oct 2022 07:51:15 -0700 (PDT) X-Google-Smtp-Source: AMsMyM56DFhAtt1SUNaXKBBXaXxhZN3zkDW4dBJwume6jybTEKj7Z6LcIthuKgHUUT5aqafLfmXpzA== X-Received: by 2002:a37:b586:0:b0:6df:fd18:386d with SMTP id e128-20020a37b586000000b006dffd18386dmr9629269qkf.114.1666277475477; Thu, 20 Oct 2022 07:51:15 -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 az14-20020a05620a170e00b006ce9e880c6fsm7281154qkb.111.2022.10.20.07.51.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 20 Oct 2022 07:51:14 -0700 (PDT) Message-ID: Date: Thu, 20 Oct 2022 10:51:14 -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++: 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/19/22 03:48, Jakub Jelinek wrote: > Hi! > > The excess precision support broke building skia (dependency of firefox) > on ia32 (it has something like the a constexpr variable), but as the other > cases show, it is actually a preexisting problem if one uses casts from > constants with wider floating point types. > The problem is that cxx_eval_constant_expression tries to short-cut > processing of TREE_CONSTANT CONSTRUCTORs if they satisfy > reduced_constant_expression_p - instead of calling cxx_eval_bare_aggregate > on them it just verifies flags and if they are TREE_CONSTANT even after > that, just fold. > Now, on the testcase we have a TREE_CONSTANT CONSTRUCTOR containing > TREE_CONSTANT NOP_EXPR of REAL_CST. And, fold, which isn't recursive, > doesn't optimize that into VECTOR_CST, while later on we are only able > to optimize VECTOR_CST arithmetics, not arithmetics with vector > CONSTRUCTORs. > The following patch fixes that by only returning what fold returned > if for vector types it returned VECTOR_CST, otherwise let us > call cxx_eval_bare_aggregate. That function will try to constant > evaluate all the elements and if anything changes, return a CONSTRUCTOR, > in the vector type cases with fold called on it at the end. > Now, just calling cxx_eval_bare_aggregate for vector types doesn't work > either (e.g. constexpr-builtin4.C breaks), because cxx_eval_bare_aggregate > if nothing changes (like all elts are already REAL_CSTs or INTEGER_CSTs) > will return the old CONSTRUCTOR and nothing folds it into a VECTOR_CST. 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. > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? > > 2022-10-19 Jakub Jelinek > > PR c++/107295 > * constexpr.cc (cxx_eval_constant_expression) : > Don't short-cut TREE_CONSTANT vector ctors if fold doesn't turn them > into VECTOR_CST. > > * g++.dg/ext/vector42.C: New test. > > --- gcc/cp/constexpr.cc.jj 2022-10-17 12:29:33.518016420 +0200 > +++ gcc/cp/constexpr.cc 2022-10-19 01:29:28.761935708 +0200 > @@ -7391,7 +7391,12 @@ cxx_eval_constant_expression (const cons > VECTOR_CST if applicable. */ > verify_constructor_flags (t); > if (TREE_CONSTANT (t)) > - return fold (t); > + { > + r = fold (t); > + if (TREE_CODE (TREE_TYPE (t)) != VECTOR_TYPE > + || TREE_CODE (r) == VECTOR_CST) > + return r; > + } > } > r = cxx_eval_bare_aggregate (ctx, t, lval, > non_constant_p, overflow_p); > --- gcc/testsuite/g++.dg/ext/vector42.C.jj 2022-10-18 12:33:42.938510483 +0200 > +++ gcc/testsuite/g++.dg/ext/vector42.C 2022-10-18 12:32:27.448544476 +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 >