From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id A95B53858412; Mon, 24 Oct 2022 15:54:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A95B53858412 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666626877; bh=XroLlH0nINvkRdQ4fAMOBx3tI/YkqxxcCsDoncwPAXQ=; h=From:To:Subject:Date:From; b=PVtiHW8WIy3bmfknvMLLy6hnbDVXtESDbwCDmd0W68mYdmwoJ1D22nliTeAD8JDOU 2qnPrs6KxM7LBfFIIX0kla9D3qp04DgW5OYBz9qP2Lc3JXY1ryv7MMqx1e6kZ7MXb0 NLpbmbJY46HAsdRVCwZ/HAGf6MmylikivFlU9UiQ= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-3461] c, c++: Fix up excess precision handling of scalar_to_vector conversion [PR107358] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: 131d18e928a3ea1ab2d3bf61aa92d68a8a254609 X-Git-Newrev: 65e3274e363cb2c6bfe6b5e648916eb7696f7e2f Message-Id: <20221024155437.A95B53858412@sourceware.org> Date: Mon, 24 Oct 2022 15:54:37 +0000 (GMT) List-Id: https://gcc.gnu.org/g:65e3274e363cb2c6bfe6b5e648916eb7696f7e2f commit r13-3461-g65e3274e363cb2c6bfe6b5e648916eb7696f7e2f Author: Jakub Jelinek Date: Mon Oct 24 17:53:16 2022 +0200 c, c++: Fix up excess precision handling of scalar_to_vector conversion [PR107358] 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) 2022-10-24 Jakub Jelinek PR c++/107358 gcc/c/ * c-typeck.cc (build_binary_op): Pass operands before excess precision promotions to scalar_to_vector call. gcc/cp/ * typeck.cc (cp_build_binary_op): Pass operands before excess precision promotions to scalar_to_vector call. gcc/testsuite/ * c-c++-common/pr107358.c: New test. * g++.dg/cpp1y/pr68180.C: Remove -fexcess-precision=fast from dg-options. Diff: --- gcc/c/c-typeck.cc | 4 ++-- gcc/cp/typeck.cc | 7 +++++-- gcc/testsuite/c-c++-common/pr107358.c | 30 ++++++++++++++++++++++++++++++ gcc/testsuite/g++.dg/cpp1y/pr68180.C | 2 +- 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc index fdb96c28c51..92f3afc5857 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -11995,8 +11995,8 @@ build_binary_op (location_t location, enum tree_code code, 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) { diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc index 16e7d85793d..530d260b1e8 100644 --- a/gcc/cp/typeck.cc +++ b/gcc/cp/typeck.cc @@ -5191,6 +5191,8 @@ cp_build_binary_op (const op_location_t &location, 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 &location, 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) { diff --git a/gcc/testsuite/c-c++-common/pr107358.c b/gcc/testsuite/c-c++-common/pr107358.c new file mode 100644 index 00000000000..4ab75e064f8 --- /dev/null +++ b/gcc/testsuite/c-c++-common/pr107358.c @@ -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; +} diff --git a/gcc/testsuite/g++.dg/cpp1y/pr68180.C b/gcc/testsuite/g++.dg/cpp1y/pr68180.C index 64d613ee5a7..9e6e5e984f9 100644 --- a/gcc/testsuite/g++.dg/cpp1y/pr68180.C +++ b/gcc/testsuite/g++.dg/cpp1y/pr68180.C @@ -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) {