public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Iain Buclaw <ibuclaw@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-6430] d: vector float comparison doesn't result in 0 or -1 [PR108945]
Date: Fri,  3 Mar 2023 00:26:13 +0000 (GMT)	[thread overview]
Message-ID: <20230303002613.10A9C3858D37@sourceware.org> (raw)

https://gcc.gnu.org/g:51af8a6401eea726d3498e6b2aba456b6af246d6

commit r13-6430-g51af8a6401eea726d3498e6b2aba456b6af246d6
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date:   Mon Feb 27 16:02:21 2023 +0100

    d: vector float comparison doesn't result in 0 or -1 [PR108945]
    
    When comparing two vectors, the type of vector was used as the result of
    the condition result.  This meant that for floating point comparisons,
    each value would either be `0.0' or `-1.0' reinterpreted as an integer,
    not the expected integral bitmask values `0' and `-1'.
    
    Instead, use the comparison type determined by truth_type_for as the
    result of the comparison.  If a reinterpret is later required by the
    final conversion for generating CmpExp, it is still only going to
    reinterpret one integer kind as another.
    
            PR d/108945
    
    gcc/d/ChangeLog:
    
            * d-codegen.cc (build_boolop): Evaluate vector comparison as
            the truth_type_for vector type.
    
    gcc/testsuite/ChangeLog:
    
            * gdc.dg/pr108945.d: New test.

Diff:
---
 gcc/d/d-codegen.cc              |  9 ++++-----
 gcc/testsuite/gdc.dg/pr108945.d | 12 ++++++++++++
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index 0e8e07366ee..5a041927ec9 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -1453,13 +1453,12 @@ build_boolop (tree_code code, tree arg0, tree arg1)
     {
       /* Build a vector comparison.
 	 VEC_COND_EXPR <e1 op e2, { -1, -1, -1, -1 }, { 0, 0, 0, 0 }>; */
-      tree type = TREE_TYPE (arg0);
-      tree cmptype = truth_type_for (type);
+      tree cmptype = truth_type_for (TREE_TYPE (arg0));
       tree cmp = fold_build2_loc (input_location, code, cmptype, arg0, arg1);
 
-      return fold_build3_loc (input_location, VEC_COND_EXPR, type, cmp,
-			      build_minus_one_cst (type),
-			      build_zero_cst (type));
+      return fold_build3_loc (input_location, VEC_COND_EXPR, cmptype, cmp,
+			      build_minus_one_cst (cmptype),
+			      build_zero_cst (cmptype));
     }
 
   if (code == EQ_EXPR || code == NE_EXPR)
diff --git a/gcc/testsuite/gdc.dg/pr108945.d b/gcc/testsuite/gdc.dg/pr108945.d
new file mode 100644
index 00000000000..03b9de8e758
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr108945.d
@@ -0,0 +1,12 @@
+// { dg-options "-fdump-tree-gimple" }
+// { dg-additional-options "-mavx" { target avx_runtime } }
+// { dg-do compile { target { avx_runtime || vect_sizes_16B_8B } } }
+
+alias f4 = __vector(float[4]);
+
+auto pr108945(f4 a, f4 b)
+{
+    return a < b;
+}
+
+// { dg-final { scan-tree-dump-not "VEC_COND_EXPR" "gimple" } }

                 reply	other threads:[~2023-03-03  0:26 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=20230303002613.10A9C3858D37@sourceware.org \
    --to=ibuclaw@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).