public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-1641] Explicitly view_convert_expr mask to signed type when folding pblendvb builtins.
@ 2023-06-09  1:42 hongtao Liu
  0 siblings, 0 replies; only message in thread
From: hongtao Liu @ 2023-06-09  1:42 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:dac73e4c64bf62be18bd5203e4e0f3e6bc64b4dc

commit r14-1641-gdac73e4c64bf62be18bd5203e4e0f3e6bc64b4dc
Author: liuhongt <hongtao.liu@intel.com>
Date:   Mon Jun 5 12:38:41 2023 +0800

    Explicitly view_convert_expr mask to signed type when folding pblendvb builtins.
    
    Since mask < 0 will be always false for vector char when
    -funsigned-char, but vpblendvb needs to check the most significant
    bit. The patch explicitly VCE to vector signed char.
    
    gcc/ChangeLog:
    
            PR target/110108
            * config/i386/i386.cc (ix86_gimple_fold_builtin): Explicitly
            view_convert_expr mask to signed type when folding pblendvb
            builtins.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.target/i386/pr110108-2.c: New test.

Diff:
---
 gcc/config/i386/i386.cc                    |  4 +++-
 gcc/testsuite/gcc.target/i386/pr110108-2.c | 14 ++++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
index 660fe15cce1..3a1444db882 100644
--- a/gcc/config/i386/i386.cc
+++ b/gcc/config/i386/i386.cc
@@ -18572,8 +18572,10 @@ ix86_gimple_fold_builtin (gimple_stmt_iterator *gsi)
 	      tree itype = GET_MODE_INNER (TYPE_MODE (type)) == E_SFmode
 		? intSI_type_node : intDI_type_node;
 	      type = get_same_sized_vectype (itype, type);
-	      arg2 = gimple_build (&stmts, VIEW_CONVERT_EXPR, type, arg2);
 	    }
+	  else
+	    type = signed_type_for (type);
+	  arg2 = gimple_build (&stmts, VIEW_CONVERT_EXPR, type, arg2);
 	  tree zero_vec = build_zero_cst (type);
 	  tree cmp_type = truth_type_for (type);
 	  tree cmp = gimple_build (&stmts, LT_EXPR, cmp_type, arg2, zero_vec);
diff --git a/gcc/testsuite/gcc.target/i386/pr110108-2.c b/gcc/testsuite/gcc.target/i386/pr110108-2.c
new file mode 100644
index 00000000000..2d1d2fd4991
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr110108-2.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-mavx2 -O2 -funsigned-char" } */
+/* { dg-final { scan-assembler-times "vpblendvb" 2 } } */
+
+#include <immintrin.h>
+__m128i do_stuff_128(__m128i X0, __m128i X1, __m128i X2) {
+  __m128i Result = _mm_blendv_epi8(X0, X1, X2);
+  return Result;
+}
+
+__m256i do_stuff_256(__m256i X0, __m256i X1, __m256i X2) {
+  __m256i Result = _mm256_blendv_epi8(X0, X1, X2);
+  return Result;
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-06-09  1:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-09  1:42 [gcc r14-1641] Explicitly view_convert_expr mask to signed type when folding pblendvb builtins hongtao Liu

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).