public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r11-10363] c, c++: Fix up excess precision handling of scalar_to_vector conversion [PR107358]
Date: Fri,  4 Nov 2022 08:31:20 +0000 (GMT)	[thread overview]
Message-ID: <20221104083120.256E6385843B@sourceware.org> (raw)

https://gcc.gnu.org/g:57da0797a73f32c879bca77e121a4f55fcc57ce1

commit r11-10363-g57da0797a73f32c879bca77e121a4f55fcc57ce1
Author: Jakub Jelinek <jakub@redhat.com>
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  <jakub@redhat.com>
    
            PR c++/107358
    gcc/c/
            * c-typeck.c (build_binary_op): Pass operands before excess precision
            promotions to scalar_to_vector call.
    gcc/testsuite/
            * c-c++-common/pr107358.c: New test.
    
    (cherry picked from commit 65e3274e363cb2c6bfe6b5e648916eb7696f7e2f)

Diff:
---
 gcc/c/c-typeck.c                      |  4 ++--
 gcc/testsuite/c-c++-common/pr107358.c | 30 ++++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index 53b86f37cad..84b44081f0e 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -11764,8 +11764,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/testsuite/c-c++-common/pr107358.c b/gcc/testsuite/c-c++-common/pr107358.c
new file mode 100644
index 00000000000..d976da7393a
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/pr107358.c
@@ -0,0 +1,30 @@
+/* PR c++/107358 */
+/* { dg-do compile { target c } } */
+/* { 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;
+}

                 reply	other threads:[~2022-11-04  8:31 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221104083120.256E6385843B@sourceware.org \
    --to=jakub@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).