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 0512F3858403 for ; Mon, 24 Oct 2022 20:03:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0512F3858403 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=1666641818; 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=H1LZoCnDTa6ByixvW8/gu5XagzM7go1IR0vTe0MKSXc=; b=GJOeW8Aj+56xnQ8jyXiOAIBM8vOoLGa3eTsW8uUC2j7eozvOK1LJFcDJdnInSsQoolHBg0 ti4HXSdQ/B8aKsOMrR7Ic8nV78WU263bKOBSQS+B61YqVR+0l5L8gAdC20Hdf69MNfkS7z AgYTgY7tPzuWTIN+x6DLnLRkDvsTEPY= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-631-0fgDIENSO1GEGcNivl9Vhw-1; Mon, 24 Oct 2022 16:03:35 -0400 X-MC-Unique: 0fgDIENSO1GEGcNivl9Vhw-1 Received: by mail-qv1-f69.google.com with SMTP id h1-20020a0ceda1000000b004b899df67a4so5804133qvr.1 for ; Mon, 24 Oct 2022 13:03: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=H1LZoCnDTa6ByixvW8/gu5XagzM7go1IR0vTe0MKSXc=; b=hfK+RdvHyeitPkwmL2ElltVffuJJ26EckOH4kPlLjz715iBtjeiQ6tdav4P9KPXkhQ 9I+YQ9Z/et1qv19P+fV6KelT6QqX8cz8/jAbKNPsFAPAuMD9LkemshlDU/RImimJIqe2 4snYge2vC2ApCGNLgTD0zU1FFzLjsMwsih4oz0KcwCgOcwYg0Soh55J2AnonPUK/Eax0 6WsRsDKR4I7juT9QUPWGEziTvJSZsTzSnSZYLtAybrzkmQhYMnhs7N6ec4YdP7hzbVSV YRqNBJAzAyeAmv5CMCo1omiujYQxqW4bhLBcYUa+eq0z10DB3/kDSZqYL6gaXAPAJJ2V ZMjg== X-Gm-Message-State: ACrzQf3jeqkh20HTFjM9DNJ7p4XuoqSiNxJHr/mjGKGJEfg90+km+nu7 1lsy7SvP+U4viWAtG/q2CxTICZZmX4hiue48+lwgnGo4bTUC88M7B9qTziefOT+/aOEMcMr0LG5 Y+X1SbyU2CeCPoO9diA== X-Received: by 2002:ac8:7d90:0:b0:39c:f9c3:6504 with SMTP id c16-20020ac87d90000000b0039cf9c36504mr26643840qtd.649.1666641814601; Mon, 24 Oct 2022 13:03:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6MQBp6mxWMZNn+YujFXLCLk1e8P3bRclYqmWMt4oZJLj5BL4txom1A/7rkYXcmoTTqTzu6hA== X-Received: by 2002:ac8:7d90:0:b0:39c:f9c3:6504 with SMTP id c16-20020ac87d90000000b0039cf9c36504mr26643810qtd.649.1666641814265; Mon, 24 Oct 2022 13:03: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 b13-20020ac86bcd000000b0039cbbcc7da8sm474668qtt.7.2022.10.24.13.03.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 24 Oct 2022 13:03:33 -0700 (PDT) Message-ID: <7deca6ca-8689-3765-99b8-c5eacff81bc5@redhat.com> Date: Mon, 24 Oct 2022 16:03:33 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.0 Subject: Re: [PATCH] c, c++: Fix up excess precision handling of scalar_to_vector conversion [PR107358] To: Jakub Jelinek , "Joseph S. Myers" 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/24/22 03:19, Jakub Jelinek wrote: > Hi! > > As mentioned earlier in the C++ excess precision support mail, the following > testcase is broken with excess precision both in C and C++ (though just in C++ > it was triggered in real-world code). > scalar_to_vector is called in both FEs after the excess precision promotions > (or stripping of EXCESS_PRECISION_EXPR), so we can then get invalid > diagnostics that say float vector + float involves truncation (on ia32 > from long double to float). > > The following patch fixes that by calling scalar_to_vector on the operands > before the excess precision promotions, let scalar_to_vector just do the > diagnostics (it does e.g. fold_for_warn so it will fold > EXCESS_PRECISION_EXPR around REAL_CST to constants etc.) but will then > do the actual conversions using the excess precision promoted operands > (so say if we have vector double + (float + float) we don't actually do > vector double + (float) ((long double) float + (long double) float) > but > vector double + (double) ((long double) float + (long double) float) > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? OK on Wednesday if Joseph doesn't object. > 2022-10-24 Jakub Jelinek > > PR c++/107358 > c/ > * c-typeck.cc (build_binary_op): Pass operands before excess precision > promotions to scalar_to_vector call. > cp/ > * typeck.cc (cp_build_binary_op): Pass operands before excess precision > promotions to scalar_to_vector call. > testsuite/ > * c-c++-common/pr107358.c: New test. > * g++.dg/cpp1y/pr68180.C: Remove -fexcess-precision=fast from > dg-options. > > --- gcc/c/c-typeck.cc.jj 2022-10-14 09:35:56.199990261 +0200 > +++ gcc/c/c-typeck.cc 2022-10-22 17:54:24.378839301 +0200 > @@ -11995,8 +11995,8 @@ build_binary_op (location_t location, en > if ((gnu_vector_type_p (type0) && code1 != VECTOR_TYPE) > || (gnu_vector_type_p (type1) && code0 != VECTOR_TYPE)) > { > - enum stv_conv convert_flag = scalar_to_vector (location, code, op0, op1, > - true); > + enum stv_conv convert_flag = scalar_to_vector (location, code, orig_op0, > + orig_op1, true); > > switch (convert_flag) > { > --- gcc/cp/typeck.cc.jj 2022-10-20 13:54:22.535670240 +0200 > +++ gcc/cp/typeck.cc 2022-10-22 17:56:58.589715301 +0200 > @@ -5191,6 +5191,8 @@ cp_build_binary_op (const op_location_t > > orig_type0 = type0 = TREE_TYPE (op0); > orig_type1 = type1 = TREE_TYPE (op1); > + tree non_ep_op0 = op0; > + tree non_ep_op1 = op1; > > /* The expression codes of the data types of the arguments tell us > whether the arguments are integers, floating, pointers, etc. */ > @@ -5303,8 +5305,9 @@ cp_build_binary_op (const op_location_t > if ((gnu_vector_type_p (type0) && code1 != VECTOR_TYPE) > || (gnu_vector_type_p (type1) && code0 != VECTOR_TYPE)) > { > - enum stv_conv convert_flag = scalar_to_vector (location, code, op0, op1, > - complain & tf_error); > + enum stv_conv convert_flag > + = scalar_to_vector (location, code, non_ep_op0, non_ep_op1, > + complain & tf_error); > > switch (convert_flag) > { > --- gcc/testsuite/c-c++-common/pr107358.c.jj 2022-10-22 18:46:59.390375310 +0200 > +++ gcc/testsuite/c-c++-common/pr107358.c 2022-10-22 18:01:52.973660719 +0200 > @@ -0,0 +1,30 @@ > +/* PR c++/107358 */ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -fexcess-precision=standard" } */ > + > +typedef float __attribute__((vector_size (4 * sizeof (float)))) A; > +typedef double __attribute__((vector_size (2 * sizeof (double)))) B; > + > +void > +foo (A *x) > +{ > + *x = *x - 124.225514990f; > +} > + > +void > +bar (A *x, float y) > +{ > + *x = *x - y; > +} > + > +void > +baz (B *x) > +{ > + *x = *x + 124.225514990f; > +} > + > +void > +qux (B *x, double y) > +{ > + *x = *x + y; > +} > --- gcc/testsuite/g++.dg/cpp1y/pr68180.C.jj 2022-10-14 09:28:28.339159477 +0200 > +++ gcc/testsuite/g++.dg/cpp1y/pr68180.C 2022-10-22 17:59:07.012946513 +0200 > @@ -1,6 +1,6 @@ > // PR c++/68180 > // { dg-do compile { target c++14 } } > -// { dg-additional-options "-Wno-psabi -fexcess-precision=fast" } > +// { dg-additional-options "-Wno-psabi" } > > typedef float __attribute__( ( vector_size( 16 ) ) ) float32x4_t; > constexpr float32x4_t fill(float x) { > > Jakub >