public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] middle-end/103485 - fix conversion kind for vectors
@ 2021-11-30  8:16 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2021-11-30  8:16 UTC (permalink / raw)
  To: gcc-patches

This makes sure to use a VIEW_CONVERT_EXPR for converting
vector signedness in the -((int)x >> (prec - 1)) to (unsigned)x >> (prec - 1)
simplification.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

2021-11-30  Richard Biener  <rguenther@suse.de>

	PR middle-end/103485
	* match.pd (-((int)x >> (prec - 1)) to (unsigned)x >> (prec - 1)):
	Use VIEW_CONVERT_EXPR for vectors.

	* gcc.dg/pr103485.c: New testcase.
---
 gcc/match.pd                    |  4 +++-
 gcc/testsuite/gcc.dg/pr103485.c | 10 ++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr103485.c

diff --git a/gcc/match.pd b/gcc/match.pd
index e14f97ee1cd..d467a1c4e45 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -1611,7 +1611,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (with { tree stype = TREE_TYPE (@0);
 	  tree ntype = TYPE_UNSIGNED (stype) ? signed_type_for (stype)
 					     : unsigned_type_for (stype); }
-   (convert (rshift:ntype (convert:ntype @0) @1)))))
+   (if (VECTOR_TYPE_P (type))
+    (view_convert (rshift (view_convert:ntype @0) @1))
+    (convert (rshift (convert:ntype @0) @1))))))
 
 /* Try to fold (type) X op CST -> (type) (X op ((type-x) CST))
    when profitable.
diff --git a/gcc/testsuite/gcc.dg/pr103485.c b/gcc/testsuite/gcc.dg/pr103485.c
new file mode 100644
index 00000000000..1afa9286924
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr103485.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+
+int foo_v256u128_0;
+unsigned __attribute__((__vector_size__ (sizeof(unsigned) * 8))) foo_v256u8_0;
+
+void
+foo (void)
+{
+  foo_v256u8_0 -= (foo_v256u8_0 >> sizeof (foo_v256u8_0) - 1) + foo_v256u128_0;
+}
-- 
2.31.1

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

only message in thread, other threads:[~2021-11-30  8:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-30  8:16 [PATCH] middle-end/103485 - fix conversion kind for vectors Richard Biener

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